ecode: Added an option to show relative lines position.

This commit is contained in:
Martín Lucas Golini
2023-03-12 22:05:57 -03:00
parent a78cdadfc3
commit de59ee7423
6 changed files with 35 additions and 3 deletions
+5 -1
View File
@@ -592,7 +592,10 @@ class EE_API UICodeEditor : public UIWidget, public TextDocument::Client {
Vector2f getRelativeScreenPosition( const TextPosition& pos );
protected:
bool getShowLinesRelativePosition() const;
void showLinesRelativePosition(bool showLinesRelativePosition);
protected:
struct LastXOffset {
TextPosition position{ 0, 0 };
Float offset{ 0.f };
@@ -628,6 +631,7 @@ class EE_API UICodeEditor : public UIWidget, public TextDocument::Client {
bool mAutoCloseXMLTags{ false };
bool mFindReplaceEnabled{ true };
bool mShowIndentationGuides{ false };
bool mShowLinesRelativePosition;
std::atomic<bool> mHighlightWordProcessing{ false };
TextRange mLinkPosition;
String mLink;
+17 -2
View File
@@ -1381,6 +1381,14 @@ Vector2f UICodeEditor::getRelativeScreenPosition( const TextPosition& pos ) {
startScroll.y + pos.line() * lineHeight + getLineOffset() };
}
bool UICodeEditor::getShowLinesRelativePosition() const {
return mShowLinesRelativePosition;
}
void UICodeEditor::showLinesRelativePosition( bool showLinesRelativePosition ) {
mShowLinesRelativePosition = showLinesRelativePosition;
}
void UICodeEditor::drawCursor( const Vector2f& startScroll, const Float& lineHeight,
const TextPosition& cursor ) {
if ( mCursorVisible && !mLocked && isTextSelectionEnabled() ) {
@@ -2871,9 +2879,16 @@ void UICodeEditor::drawLineNumbers( const std::pair<int, int>& lineRange,
primitives.drawRectangle( Rectf( screenStart, Sizef( lineNumberWidth, mSize.getHeight() ) ) );
TextRange selection = mDoc->getSelection( true );
Float lineOffset = getLineOffset();
for ( int i = lineRange.first; i <= lineRange.second; i++ ) {
Text line( String( String::toString( i + 1 ) ).padLeft( lineNumberDigits, ' ' ), mFont,
fontSize );
String pos;
if ( mShowLinesRelativePosition && selection.start().line() != i ) {
pos = String( String::toString( eeabs( i - selection.start().line() ) ) )
.padLeft( lineNumberDigits, ' ' );
} else {
pos = String( String::toString( i + 1 ) ).padLeft( lineNumberDigits, ' ' );
}
Text line( std::move( pos ), mFont, fontSize );
line.setStyleConfig( mFontStyleConfig );
line.setColor( ( i >= selection.start().line() && i <= selection.end().line() )
? mLineNumberActiveFontColor
+2
View File
@@ -130,6 +130,7 @@ void AppConfig::load( const std::string& confPath, std::string& keybindingsPath,
editor.lineSpacing = ini.getValue( "editor", "line_spacing", "0dp" );
editor.cursorBlinkingTime =
Time::fromString( ini.getValue( "editor", "cursor_blinking_time", "0.5s" ) );
editor.linesRelativePosition = ini.getValueB( "editor", "lines_relative_position", false );
searchBarConfig.caseSensitive = ini.getValueB( "search_bar", "case_sensitive", false );
searchBarConfig.luaPattern = ini.getValueB( "search_bar", "lua_pattern", false );
@@ -240,6 +241,7 @@ void AppConfig::save( const std::vector<std::string>& recentFiles,
ini.setValueB( "editor", "auto_close_xml_tags", editor.autoCloseXMLTags );
ini.setValue( "editor", "line_spacing", editor.lineSpacing.toString() );
ini.setValue( "editor", "cursor_blinking_time", editor.cursorBlinkingTime.toString() );
ini.setValueB( "editor", "lines_relative_position", editor.linesRelativePosition );
ini.setValueB( "search_bar", "case_sensitive", searchBarConfig.caseSensitive );
ini.setValueB( "search_bar", "lua_pattern", searchBarConfig.luaPattern );
+1
View File
@@ -69,6 +69,7 @@ struct CodeEditorConfig {
bool singleClickTreeNavigation{ false };
bool syncProjectTreeWithEditor{ true };
bool autoCloseXMLTags{ true };
bool linesRelativePosition{ false };
std::string autoCloseBrackets{ "" };
Time cursorBlinkingTime{ Seconds( 0.5f ) };
};
+1
View File
@@ -2081,6 +2081,7 @@ void App::onCodeEditorCreated( UICodeEditor* editor, TextDocument& doc ) {
editor->addEventListener( Event::OnEditorTabReady, docChanged );
editor->showMinimap( config.minimap );
editor->showLinesRelativePosition( config.linesRelativePosition );
mPluginManager->onNewEditor( editor );
}
+9
View File
@@ -1085,6 +1085,9 @@ UIMenu* SettingsMenu::createViewMenu() {
mViewMenu->addCheckBox( i18n( "highlight_matching_brackets", "Highlight Matching Bracket" ) )
->setActive( mApp->getConfig().editor.highlightMatchingBracket )
->setId( "highlight-matching-brackets" );
mViewMenu->addCheckBox( i18n( "show_lines_relative_position", "Show Lines Relative Position" ) )
->setActive( mApp->getConfig().editor.linesRelativePosition )
->setId( "show-lines-relative-position" );
mViewMenu->addCheckBox( i18n( "highlight_current_line", "Highlight Current Line" ) )
->setActive( mApp->getConfig().editor.highlightCurrentLine )
->setId( "highlight-current-line" );
@@ -1166,6 +1169,12 @@ UIMenu* SettingsMenu::createViewMenu() {
mSplitter->forEachEditor( [&]( UICodeEditor* editor ) {
editor->showMinimap( mApp->getConfig().editor.minimap );
} );
} else if ( item->getId() == "show-lines-relative-position" ) {
mApp->getConfig().editor.linesRelativePosition =
item->asType<UIMenuCheckBox>()->isActive();
mSplitter->forEachEditor( [&]( UICodeEditor* editor ) {
editor->showLinesRelativePosition( mApp->getConfig().editor.linesRelativePosition );
} );
} else if ( item->getId() == "highlight-matching-brackets" ) {
mApp->getConfig().editor.highlightMatchingBracket =
item->asType<UIMenuCheckBox>()->isActive();