mirror of
https://github.com/SpartanJ/eepp.git
synced 2026-06-04 20:46:29 +03:00
Restore syntax custom style support.
This commit is contained in:
@@ -9,6 +9,7 @@
|
||||
#include <eepp/system/log.hpp>
|
||||
#include <eepp/system/packmanager.hpp>
|
||||
#include <eepp/ui/doc/syntaxcolorscheme.hpp>
|
||||
#include <eepp/ui/doc/syntaxdefinition.hpp>
|
||||
|
||||
using namespace EE::Graphics;
|
||||
|
||||
@@ -230,15 +231,7 @@ SyntaxColorScheme::getSyntaxStyle( const SyntaxStyleType& type ) const {
|
||||
auto foundIt = mStyleCache.find( type );
|
||||
if ( foundIt != mStyleCache.end() )
|
||||
return foundIt->second;
|
||||
/*bool colorWasSet;
|
||||
mStyleCache[type] = parseStyle( type, &colorWasSet, &mSyntaxColors );
|
||||
if ( !colorWasSet ) {
|
||||
auto normalStyle = mSyntaxColors.find( "normal"_sst );
|
||||
if ( normalStyle != mSyntaxColors.end() ) {
|
||||
mStyleCache[type].color = normalStyle->second.color;
|
||||
}
|
||||
}
|
||||
return mStyleCache[type];*/
|
||||
return getSyntaxStyleFromCache<SyntaxStyleType>( type );
|
||||
}
|
||||
return StyleEmpty;
|
||||
}
|
||||
@@ -314,4 +307,26 @@ void SyntaxColorScheme::setName( const std::string& name ) {
|
||||
mName = name;
|
||||
}
|
||||
|
||||
template <typename SyntaxStyleType>
|
||||
const SyntaxColorScheme::Style&
|
||||
SyntaxColorScheme::getSyntaxStyleFromCache( const SyntaxStyleType& type ) const {
|
||||
bool colorWasSet = false;
|
||||
if constexpr ( std::is_same_v<SyntaxStyleType, std::string> )
|
||||
mStyleCache[type] = parseStyle( type, &colorWasSet, &mSyntaxColors );
|
||||
else {
|
||||
auto cache = SyntaxPattern::SyntaxStyleTypeCache.find( type );
|
||||
if ( cache != SyntaxPattern::SyntaxStyleTypeCache.end() ) {
|
||||
mStyleCache[type] = parseStyle( cache->second, &colorWasSet );
|
||||
} else {
|
||||
return StyleEmpty;
|
||||
}
|
||||
}
|
||||
if ( !colorWasSet ) {
|
||||
auto normalStyle = mSyntaxColors.find( "normal"_sst );
|
||||
if ( normalStyle != mSyntaxColors.end() )
|
||||
mStyleCache[type].color = normalStyle->second.color;
|
||||
}
|
||||
return mStyleCache[type];
|
||||
}
|
||||
|
||||
}}} // namespace EE::UI::Doc
|
||||
|
||||
@@ -4,6 +4,22 @@
|
||||
|
||||
namespace EE { namespace UI { namespace Doc {
|
||||
|
||||
UnorderedMap<SyntaxStyleType, std::string> SyntaxPattern::SyntaxStyleTypeCache = {};
|
||||
|
||||
template <typename SyntaxStyleType> void updateCache( const SyntaxPattern& ptrn ) {
|
||||
if constexpr ( std::is_same_v<SyntaxStyleType, std::string> ) {
|
||||
return;
|
||||
} else {
|
||||
for ( size_t i = 0; i < ptrn.typesNames.size(); i++ ) {
|
||||
if ( SyntaxStyleTypes::needsToBeCached( ptrn.types[i] ) ) {
|
||||
auto it = SyntaxPattern::SyntaxStyleTypeCache.find( ptrn.types[i] );
|
||||
if ( it == SyntaxPattern::SyntaxStyleTypeCache.end() )
|
||||
SyntaxPattern::SyntaxStyleTypeCache[ptrn.types[i]] = ptrn.typesNames[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
SyntaxDefinition::SyntaxDefinition() {}
|
||||
|
||||
SyntaxDefinition::SyntaxDefinition( const std::string& languageName,
|
||||
@@ -208,4 +224,40 @@ const String::HashType& SyntaxDefinition::getLanguageId() const {
|
||||
return mLanguageId;
|
||||
}
|
||||
|
||||
SyntaxPattern::SyntaxPattern( std::vector<std::string>&& _patterns, const std::string& _type,
|
||||
const std::string& _syntax ) :
|
||||
patterns( std::move( _patterns ) ),
|
||||
types( toSyntaxStyleTypeV( std::vector<std::string>{ _type } ) ),
|
||||
typesNames( { _type } ),
|
||||
syntax( _syntax ) {
|
||||
updateCache<SyntaxStyleType>( *this );
|
||||
}
|
||||
|
||||
SyntaxPattern::SyntaxPattern( std::vector<std::string>&& _patterns,
|
||||
std::vector<std::string>&& _types, const std::string& _syntax ) :
|
||||
patterns( std::move( _patterns ) ),
|
||||
types( toSyntaxStyleTypeV( _types ) ),
|
||||
typesNames( std::move( _types ) ),
|
||||
syntax( _syntax ) {
|
||||
updateCache<SyntaxStyleType>( *this );
|
||||
}
|
||||
|
||||
SyntaxPattern::SyntaxPattern( std::vector<std::string>&& _patterns, const std::string& _type,
|
||||
DynamicSyntax&& _syntax ) :
|
||||
patterns( std::move( _patterns ) ),
|
||||
types( toSyntaxStyleTypeV( std::vector<std::string>{ _type } ) ),
|
||||
typesNames( { _type } ),
|
||||
dynSyntax( std::move( _syntax ) ) {
|
||||
updateCache<SyntaxStyleType>( *this );
|
||||
}
|
||||
|
||||
SyntaxPattern::SyntaxPattern( std::vector<std::string>&& _patterns,
|
||||
std::vector<std::string>&& _types, DynamicSyntax&& _syntax ) :
|
||||
patterns( std::move( _patterns ) ),
|
||||
types( toSyntaxStyleTypeV( _types ) ),
|
||||
typesNames( std::move( _types ) ),
|
||||
dynSyntax( std::move( _syntax ) ) {
|
||||
updateCache<SyntaxStyleType>( *this );
|
||||
}
|
||||
|
||||
}}} // namespace EE::UI::Doc
|
||||
|
||||
@@ -915,7 +915,7 @@ static void addYAML() {
|
||||
{ { "'", "'", "\\" }, "string" },
|
||||
{ { "%-?%.inf" }, "number" },
|
||||
{ { "%.NaN" }, "number" },
|
||||
{ { "(%&)(%g+)" }, { "keyword", "literal", "" } },
|
||||
{ { "(%&)(%g+)" }, { "normal", "keyword", "literal" } },
|
||||
{ { "!%g+" }, "keyword" },
|
||||
{ { "<<" }, "literal" },
|
||||
{ { "https?://[%w_.~!*:@&+$/?%%#-]-%w[-.%w]*%.%w%w%w?%w?:?%d*/?[%w_.~!*:@&+$/"
|
||||
|
||||
Reference in New Issue
Block a user