diff --git a/include/eepp/ui/uicodeeditor.hpp b/include/eepp/ui/uicodeeditor.hpp index 82cf1a0d5..509a2733c 100644 --- a/include/eepp/ui/uicodeeditor.hpp +++ b/include/eepp/ui/uicodeeditor.hpp @@ -562,6 +562,10 @@ class EE_API UICodeEditor : public UIWidget, public TextDocument::Client { void setScroll( const Vector2f& val, bool emmitEvent = true ); + bool getShowLineEndings() const; + + void setShowLineEndings( bool showLineEndings ); + protected: struct LastXOffset { TextPosition position; @@ -578,6 +582,7 @@ class EE_API UICodeEditor : public UIWidget, public TextDocument::Client { bool mMouseDown{ false }; bool mShowLineNumber{ true }; bool mShowWhitespaces{ true }; + bool mShowLineEndings{ false }; bool mLocked{ false }; bool mHighlightCurrentLine{ true }; bool mHighlightMatchingBracket{ true }; @@ -768,6 +773,9 @@ class EE_API UICodeEditor : public UIWidget, public TextDocument::Client { virtual void drawWhitespaces( const std::pair& lineRange, const Vector2f& startScroll, const Float& lineHeight ); + virtual void drawLineEndings( const std::pair& lineRange, const Vector2f& startScroll, + const Float& lineHeight ); + virtual void drawTextRange( const TextRange& range, const std::pair& lineRange, const Vector2f& startScroll, const Float& lineHeight, const Color& backgroundColor ); diff --git a/src/eepp/ui/uicodeeditor.cpp b/src/eepp/ui/uicodeeditor.cpp index fc842f975..94d195ec3 100644 --- a/src/eepp/ui/uicodeeditor.cpp +++ b/src/eepp/ui/uicodeeditor.cpp @@ -277,6 +277,10 @@ void UICodeEditor::draw() { drawWhitespaces( lineRange, startScroll, lineHeight ); } + if ( mShowLineEndings ) { + drawLineEndings( lineRange, startScroll, lineHeight ); + } + for ( unsigned long i = lineRange.first; i <= lineRange.second; i++ ) { Vector2f curScroll( { startScroll.x, static_cast( startScroll.y + lineHeight * (double)i ) } ); @@ -1349,7 +1353,7 @@ void UICodeEditor::findLongestLine() { Float UICodeEditor::getLineWidth( const Int64& lineIndex ) { if ( mFont && !mFont->isMonospace() ) - return getLineText( lineIndex ).getTextWidth(); + return getLineText( lineIndex ).getTextWidth() + getGlyphWidth(); return getTextWidth( mDoc->line( lineIndex ).getText() ); } @@ -1857,6 +1861,17 @@ void UICodeEditor::setScroll( const Vector2f& val, bool emmitEvent ) { setScrollY( val.y, emmitEvent ); } +bool UICodeEditor::getShowLineEndings() const { + return mShowLineEndings; +} + +void UICodeEditor::setShowLineEndings( bool showLineEndings ) { + if ( mShowLineEndings != showLineEndings ) { + mShowLineEndings = showLineEndings; + invalidateDraw(); + } +} + UICodeEditor* UICodeEditor::setFontStyle( const Uint32& fontStyle ) { if ( mFontStyleConfig.Style != fontStyle ) { mFontStyleConfig.Style = fontStyle; @@ -2765,6 +2780,23 @@ void UICodeEditor::drawWhitespaces( const std::pair& lineRange, } } +void UICodeEditor::drawLineEndings( const std::pair& lineRange, + const Vector2f& startScroll, const Float& lineHeight ) { + + Color color( Color( mWhitespaceColor ).blendAlpha( mAlpha ) ); + unsigned int fontSize = getCharacterSize(); + GlyphDrawable* nl = mFont->getGlyphDrawable( L'↴', fontSize ); + if ( nl->getPixelsSize() == Sizef::Zero ) + nl = mFont->getGlyphDrawable( L'¬', fontSize ); + nl->setDrawMode( GlyphDrawable::DrawMode::Text ); + nl->setColor( color ); + for ( int index = lineRange.first; index <= lineRange.second; index++ ) { + Vector2f position( { startScroll.x + getLineWidth( index ) - getGlyphWidth(), + startScroll.y + lineHeight * index } ); + nl->draw( Vector2f( position.x, position.y ) ); + } +} + void UICodeEditor::registerCommands() { mDoc->setCommand( "move-to-previous-line", [&] { moveToPreviousLine(); } ); mDoc->setCommand( "move-to-next-line", [&] { moveToNextLine(); } ); diff --git a/src/tools/ecode/appconfig.cpp b/src/tools/ecode/appconfig.cpp index 0a1cf2bec..ecdb4b280 100644 --- a/src/tools/ecode/appconfig.cpp +++ b/src/tools/ecode/appconfig.cpp @@ -78,6 +78,7 @@ void AppConfig::load( const std::string& confPath, std::string& keybindingsPath, windowState.position.y = iniState.getValueI( "window", "y", -1 ); editor.showLineNumbers = ini.getValueB( "editor", "show_line_numbers", true ); editor.showWhiteSpaces = ini.getValueB( "editor", "show_white_spaces", true ); + editor.showLineEndings = ini.getValueB( "editor", "show_line_endings", true ); editor.highlightMatchingBracket = ini.getValueB( "editor", "highlight_matching_brackets", true ); editor.highlightCurrentLine = ini.getValueB( "editor", "highlight_current_line", true ); @@ -187,6 +188,7 @@ void AppConfig::save( const std::vector& recentFiles, String::join( urlEncode( recentFolders ), ';' ) ); ini.setValueB( "editor", "show_line_numbers", editor.showLineNumbers ); ini.setValueB( "editor", "show_white_spaces", editor.showWhiteSpaces ); + ini.setValueB( "editor", "show_line_endings", editor.showLineEndings ); ini.setValueB( "editor", "highlight_matching_brackets", editor.highlightMatchingBracket ); ini.setValueB( "editor", "highlight_current_line", editor.highlightCurrentLine ); ini.setValueB( "editor", "vertical_scrollbar", editor.verticalScrollbar ); diff --git a/src/tools/ecode/appconfig.hpp b/src/tools/ecode/appconfig.hpp index 7e786134c..34251f260 100644 --- a/src/tools/ecode/appconfig.hpp +++ b/src/tools/ecode/appconfig.hpp @@ -49,6 +49,7 @@ struct CodeEditorConfig { StyleSheetLength lineSpacing{ 0, StyleSheetLength::Dp }; bool showLineNumbers{ true }; bool showWhiteSpaces{ true }; + bool showLineEndings{ false }; bool highlightMatchingBracket{ true }; bool verticalScrollbar{ true }; bool horizontalScrollbar{ true }; diff --git a/src/tools/ecode/ecode.cpp b/src/tools/ecode/ecode.cpp index 2915470ad..e1e29d98d 100644 --- a/src/tools/ecode/ecode.cpp +++ b/src/tools/ecode/ecode.cpp @@ -1576,6 +1576,7 @@ void App::onCodeEditorCreated( UICodeEditor* editor, TextDocument& doc ) { editor->setColorScheme( mSplitter->getCurrentColorScheme() ); editor->setShowLineNumber( config.showLineNumbers ); editor->setShowWhitespaces( config.showWhiteSpaces ); + editor->setShowLineEndings( config.showLineEndings ); editor->setHighlightMatchingBracket( config.highlightMatchingBracket ); editor->setVerticalScrollBarEnabled( config.verticalScrollbar ); editor->setHorizontalScrollBarEnabled( config.horizontalScrollbar ); diff --git a/src/tools/ecode/ecode.hpp b/src/tools/ecode/ecode.hpp index 0261d9a06..47c39988e 100644 --- a/src/tools/ecode/ecode.hpp +++ b/src/tools/ecode/ecode.hpp @@ -223,8 +223,7 @@ class App : public UICodeEditorSplitter::Client { t.setCommand( "terminal-font-size", [&] { setTerminalFontSize(); } ); t.setCommand( "ui-font-size", [&] { setUIFontSize(); } ); t.setCommand( "serif-font", [&] { openFontDialog( mConfig.ui.serifFont, false ); } ); - t.setCommand( "monospace-font", - [&] { openFontDialog( mConfig.ui.monospaceFont, false ); } ); + t.setCommand( "monospace-font", [&] { openFontDialog( mConfig.ui.monospaceFont, true ); } ); t.setCommand( "terminal-font", [&] { openFontDialog( mConfig.ui.terminalFont, false ); } ); t.setCommand( "fallback-font", [&] { openFontDialog( mConfig.ui.fallbackFont, false ); } ); mSplitter->registerSplitterCommands( t ); diff --git a/src/tools/ecode/settingsmenu.cpp b/src/tools/ecode/settingsmenu.cpp index 8d7f4dc9a..52806f2ef 100644 --- a/src/tools/ecode/settingsmenu.cpp +++ b/src/tools/ecode/settingsmenu.cpp @@ -1007,6 +1007,9 @@ UIMenu* SettingsMenu::createViewMenu() { mViewMenu->addCheckBox( i18n( "show_white_spaces", "Show White Spaces" ) ) ->setActive( mApp->getConfig().editor.showWhiteSpaces ) ->setId( "show-white-spaces" ); + mViewMenu->addCheckBox( i18n( "show_line_endings", "Show Line Endings" ) ) + ->setActive( mApp->getConfig().editor.showLineEndings ) + ->setId( "show-line-endings" ); mViewMenu->addCheckBox( i18n( "show_doc_info", "Show Document Info" ) ) ->setActive( mApp->getConfig().editor.showDocInfo ) ->setId( "show-doc-info" ); @@ -1075,6 +1078,11 @@ UIMenu* SettingsMenu::createViewMenu() { mSplitter->forEachEditor( [&]( UICodeEditor* editor ) { editor->setShowWhitespaces( mApp->getConfig().editor.showWhiteSpaces ); } ); + } else if ( item->getId() == "show-line-endings" ) { + mApp->getConfig().editor.showLineEndings = item->asType()->isActive(); + mSplitter->forEachEditor( [&]( UICodeEditor* editor ) { + editor->setShowLineEndings( mApp->getConfig().editor.showLineEndings ); + } ); } else if ( item->getId() == "show-doc-info" ) { mApp->getConfig().editor.showDocInfo = item->asType()->isActive(); if ( mApp->getDocInfo() )