LineWrapping refactor WIP. Also reduced minimap draw calls (instead of per-line now are per-frame).

This commit is contained in:
Martín Lucas Golini
2024-05-23 20:41:31 -03:00
parent 2b0c59c658
commit c6f9f10814
12 changed files with 255 additions and 229 deletions

View File

@@ -1105,31 +1105,29 @@ void LinterPlugin::drawAfterLineText( UICodeEditor* editor, const Int64& index,
}
}
void LinterPlugin::minimapDrawBeforeLineText(
UICodeEditor* editor, const Int64& index, const Vector2f& /*pos*/, const Vector2f& /*size*/,
const Float&, const Float&,
const std::function<void( const TextRanges& /*ranges*/, const Color& /*backgroundColor*/,
bool /*drawCompleteLine*/ )>
drawTextRanges ) {
void LinterPlugin::minimapDrawBefore( UICodeEditor* editor, const DocumentLineRange& docLineRange,
const DocumentViewLineRange&, const Vector2f& /*linePos*/,
const Vector2f& /*lineSize*/, const Float& /*charWidth*/,
const Float& /*gutterWidth*/,
const DrawTextRangesFn& drawTextRanges ) {
Lock l( mMatchesMutex );
auto matchIt = mMatches.find( editor->getDocumentRef().get() );
if ( matchIt == mMatches.end() )
return;
const std::map<Int64, std::vector<LinterMatch>>& map = matchIt->second;
auto lineIt = map.find( index );
if ( lineIt == map.end() )
return;
TextDocument* doc = matchIt->first;
const std::vector<LinterMatch>& matches = lineIt->second;
for ( const auto& match : matches ) {
if ( match.lineCache != doc->line( index ).getHash() )
return;
Color col(
editor->getColorScheme().getEditorSyntaxStyle( getMatchString( match.type ) ).color );
col.blendAlpha( 100 );
drawTextRanges( match.range, col, true );
break;
for ( const auto& matches : matchIt->second ) {
for ( const auto& match : matches.second ) {
if ( match.range.intersectsLineRange( docLineRange ) ) {
if ( match.lineCache != doc->line( match.range.start().line() ).getHash() )
return;
Color col( editor->getColorScheme()
.getEditorSyntaxStyle( getMatchString( match.type ) )
.color );
col.blendAlpha( 100 );
drawTextRanges( match.range, col, true );
}
}
}
}

View File

@@ -84,10 +84,11 @@ class LinterPlugin : public Plugin {
void drawAfterLineText( UICodeEditor* editor, const Int64& index, Vector2f position,
const Float& fontSize, const Float& lineHeight );
void minimapDrawBeforeLineText(
UICodeEditor*, const Int64&, const Vector2f&, const Vector2f&, const Float&, const Float&,
const std::function<void( const TextRanges& /*ranges*/, const Color& /*backgroundColor*/,
bool /*drawCompleteLine*/ )> /* drawTextRanges */ );
void minimapDrawBefore( UICodeEditor* /*editor*/, const DocumentLineRange&,
const DocumentViewLineRange&, const Vector2f& /*linePos*/,
const Vector2f& /*lineSize*/, const Float& /*charWidth*/,
const Float& /*gutterWidth*/,
const DrawTextRangesFn& /* drawTextRanges */ );
void update( UICodeEditor* );

View File

@@ -133,6 +133,19 @@ bool XMLToolsPlugin::isOverMatch( TextDocument* doc, const Int64& index ) const
return true;
}
bool XMLToolsPlugin::isVisibleInRange( TextDocument* doc, const DocumentLineRange& docLineRange ) {
if ( mMatches.empty() )
return false;
auto clientIt = mMatches.find( doc );
if ( clientIt == mMatches.end() )
return false;
const ClientMatch& match = clientIt->second;
if ( !match.matchBracket.inSameLine() && !match.currentBracket.inSameLine() )
return false;
return match.matchBracket.intersectsLineRange( docLineRange ) ||
match.currentBracket.intersectsLineRange( docLineRange );
}
static bool isClosedTag( TextDocument* doc, TextPosition start ) {
SyntaxHighlighter* highlighter = doc->getHighlighter();
TextPosition endOfDoc = doc->endOfDoc();
@@ -367,23 +380,19 @@ void XMLToolsPlugin::drawBeforeLineText( UICodeEditor* editor, const Int64& inde
}
}
void XMLToolsPlugin::minimapDrawAfterLineText(
UICodeEditor* editor, const Int64& index, const Vector2f& /*pos*/, const Vector2f& /*size*/,
const Float&, const Float&,
const std::function<void( const TextRanges& /*ranges*/, const Color& /*backgroundColor*/,
bool /*drawCompleteLine*/ )>
drawTextRanges ) {
if ( !isOverMatch( &editor->getDocument(), index ) )
void XMLToolsPlugin::minimapDrawAfter( UICodeEditor* editor, const DocumentLineRange& docLineRange,
const DocumentViewLineRange&, const Vector2f& /*linePos*/,
const Vector2f& /*lineSize*/, const Float& /*charWidth*/,
const Float& /*gutterWidth*/,
const DrawTextRangesFn& drawTextRanges ) {
if ( !isVisibleInRange( &editor->getDocument(), docLineRange ) )
return;
Primitives p;
Color color( editor->getColorScheme().getEditorSyntaxStyle( "matching_bracket"_sst ).color );
Color blendedColor( Color( color, 50 ) );
p.setColor( blendedColor );
const ClientMatch& match = mMatches[&editor->getDocument()];
for ( const auto& range : { match.matchBracket, match.currentBracket } ) {
if ( range.start().line() != index || !range.inSameLine() )
continue;
drawTextRanges( range, blendedColor, true );
}
}

View File

@@ -43,10 +43,10 @@ class XMLToolsPlugin : public PluginBase {
void drawBeforeLineText( UICodeEditor* editor, const Int64& index, Vector2f position,
const Float& fontSize, const Float& lineHeight ) override;
void minimapDrawAfterLineText(
UICodeEditor*, const Int64&, const Vector2f&, const Vector2f&, const Float&, const Float&,
const std::function<void( const TextRanges& /*ranges*/, const Color& /*backgroundColor*/,
bool /*drawCompleteLine*/ )> /* drawTextRanges */ ) override;
void minimapDrawAfter( UICodeEditor*, const DocumentLineRange&, const DocumentViewLineRange&,
const Vector2f& /*linePos*/, const Vector2f& /*lineSize*/,
const Float& /*charWidth*/, const Float& /*gutterWidth*/,
const DrawTextRangesFn& ) override;
protected:
bool mHighlightMatch{ true };
@@ -115,6 +115,8 @@ class XMLToolsPlugin : public PluginBase {
virtual void onUnregisterDocument( TextDocument* doc ) override;
bool isOverMatch( TextDocument* doc, const Int64& index ) const;
bool isVisibleInRange( TextDocument* doc, const DocumentLineRange& docLineRange );
};
} // namespace ecode