Fixes for the UITabWidget tab switcher.

Remove "Flash Cursor" (it was too broken and it's not useful after alll).
This commit is contained in:
Martín Lucas Golini
2025-05-27 01:13:44 -03:00
parent dcea675e5b
commit e072649221
10 changed files with 51 additions and 74 deletions
-2
View File
@@ -37,7 +37,6 @@ Diese Operation kann nicht rückgängig gemacht werden!</string>
<string name="ai_conversations_history">KI-Unterhaltungen</string> <string name="ai_conversations_history">KI-Unterhaltungen</string>
<string name="ai_llm_presentation">Womit kann ich helfen?</string> <string name="ai_llm_presentation">Womit kann ich helfen?</string>
<string name="ai_rename_chat">Unterhaltung umbenennen</string> <string name="ai_rename_chat">Unterhaltung umbenennen</string>
<string name="allow_flash_cursor">Blinkende Eingabemarke erlauben</string>
<string name="any_https_or_http_url">Jegliche http(s)/URLs</string> <string name="any_https_or_http_url">Jegliche http(s)/URLs</string>
<string name="any_name_ellipsis">Jeglicher Name...</string> <string name="any_name_ellipsis">Jeglicher Name...</string>
<string name="app_output">Programmrückgabe</string> <string name="app_output">Programmrückgabe</string>
@@ -321,7 +320,6 @@ ecode versucht, externes Terminal zu öffnen.</string>
<string name="find_prev">Voriges finden</string> <string name="find_prev">Voriges finden</string>
<string name="find_replace">Suchen/Ersetzen</string> <string name="find_replace">Suchen/Ersetzen</string>
<string name="find_text">Suchen:</string> <string name="find_text">Suchen:</string>
<string name="flash_cursor">Eingabemarke aufblinken</string>
<string name="folder_project_settings">Ordner/Projekteinstellungen</string> <string name="folder_project_settings">Ordner/Projekteinstellungen</string>
<string name="folder_settings">Ordner/Projekteinstellungen</string> <string name="folder_settings">Ordner/Projekteinstellungen</string>
<string name="folds_refresh_freq">Blockfaltungsaktualisierungsfrequenz</string> <string name="folds_refresh_freq">Blockfaltungsaktualisierungsfrequenz</string>
-2
View File
@@ -22,7 +22,6 @@ This operation cannot be reverted!</string>
<string name="ai_conversations_history">AI Conversations History</string> <string name="ai_conversations_history">AI Conversations History</string>
<string name="ai_llm_presentation">What can I help with?</string> <string name="ai_llm_presentation">What can I help with?</string>
<string name="ai_rename_chat">Rename Conversation</string> <string name="ai_rename_chat">Rename Conversation</string>
<string name="allow_flash_cursor">Allow Flashing Cursor</string>
<string name="any_https_or_http_url">Any https or http URL</string> <string name="any_https_or_http_url">Any https or http URL</string>
<string name="any_name_ellipsis">Any name...</string> <string name="any_name_ellipsis">Any name...</string>
<string name="app_output">App Output</string> <string name="app_output">App Output</string>
@@ -306,7 +305,6 @@ ecode will try to open an external terminal.</string>
<string name="find_prev">Find Prev</string> <string name="find_prev">Find Prev</string>
<string name="find_replace">Find Replace</string> <string name="find_replace">Find Replace</string>
<string name="find_text">Find:</string> <string name="find_text">Find:</string>
<string name="flash_cursor">Flash Cursor</string>
<string name="folder_project_settings">Folder/Project Settings</string> <string name="folder_project_settings">Folder/Project Settings</string>
<string name="folder_settings">Folder/Project Settings</string> <string name="folder_settings">Folder/Project Settings</string>
<string name="folds_refresh_freq">Folds Refresh Frequency</string> <string name="folds_refresh_freq">Folds Refresh Frequency</string>
-4
View File
@@ -931,8 +931,6 @@ class EE_API UICodeEditor : public UIWidget, public TextDocument::Client {
String::HashType mTagFoldRange{ 0 }; String::HashType mTagFoldRange{ 0 };
Uint32 mTabIndentCharacter{ 187 /*'»'*/ }; Uint32 mTabIndentCharacter{ 187 /*'»'*/ };
CharacterAlignment mTabIndentAlignment{ CharacterAlignment::Center }; CharacterAlignment mTabIndentAlignment{ CharacterAlignment::Center };
Uint32 mModDownCount{ 0 };
Clock mModDownClock;
UICodeEditor( const std::string& elementTag, const bool& autoRegisterBaseCommands = true, UICodeEditor( const std::string& elementTag, const bool& autoRegisterBaseCommands = true,
const bool& autoRegisterBaseKeybindings = true ); const bool& autoRegisterBaseKeybindings = true );
@@ -1139,8 +1137,6 @@ class EE_API UICodeEditor : public UIWidget, public TextDocument::Client {
bool isNotMonospace() const; bool isNotMonospace() const;
void flashCursor();
void setCodeEditorFlags( std::string flags, bool enable ); void setCodeEditorFlags( std::string flags, bool enable );
std::string getCodeEditorFlags( bool enabled ) const; std::string getCodeEditorFlags( bool enabled ) const;
+6
View File
@@ -244,10 +244,12 @@ class EE_API UITabWidget : public UIWidget {
bool mDroppableHoveringColorWasSet{ false }; bool mDroppableHoveringColorWasSet{ false };
bool mEnabledCreateContextMenu{ false }; bool mEnabledCreateContextMenu{ false };
bool mEnableTabSwitcher{ false }; bool mEnableTabSwitcher{ false };
bool mTabSwitcherRunning{ false };
Float mTabVerticalDragResistance; Float mTabVerticalDragResistance;
Color mDroppableHoveringColor{ Color::Transparent }; Color mDroppableHoveringColor{ Color::Transparent };
FocusTabBehavior mFocusTabBehavior{ FocusTabBehavior::Closest }; FocusTabBehavior mFocusTabBehavior{ FocusTabBehavior::Closest };
std::deque<UITab*> mFocusHistory; std::deque<UITab*> mFocusHistory;
std::deque<UITab*> mFocusHistoryFreezed;
UIPopUpMenu* mCurrentMenu{ nullptr }; UIPopUpMenu* mCurrentMenu{ nullptr };
SplitFunctionCb mSplitFn; SplitFunctionCb mSplitFn;
Float mSplitEdgePercent{ 0.1 }; Float mSplitEdgePercent{ 0.1 };
@@ -306,7 +308,11 @@ class EE_API UITabWidget : public UIWidget {
void createTabSwitcher( const std::vector<Keycode>& tabSwitcherMetaTrigger, void createTabSwitcher( const std::vector<Keycode>& tabSwitcherMetaTrigger,
bool fromPrev = false ); bool fromPrev = false );
void enableTabSwitcher( const std::vector<Keycode>& tabSwitcherMetaTrigger );
Uint32 getTabSelectedFocusHistoryIndex() const; Uint32 getTabSelectedFocusHistoryIndex() const;
Uint32 getTabSelectedFocusHistoryFreezedIndex() const;
}; };
}} // namespace EE::UI }} // namespace EE::UI
-39
View File
@@ -1138,28 +1138,6 @@ Uint32 UICodeEditor::onTextEditing( const TextEditingEvent& event ) {
return 1; return 1;
} }
void UICodeEditor::flashCursor() {
Vector2f screenStart( getScreenStart() );
Vector2f start( screenStart.x + getGutterWidth(), screenStart.y + getPluginsTopSpace() );
Vector2f startScroll( start - mScroll );
auto offset = getTextPositionOffset( mDoc->getSelection().start(), getLineHeight() );
Vector2f cursorPos( startScroll.x + offset.x - getFontHeight() * 0.5f,
startScroll.y + offset.y );
UIWidget* widget = UIWidget::New();
widget->setBorderColor( Color( mCaretColor ).blendAlpha( 100 ).blendAlpha( mAlpha ) );
widget->setPixelsPosition( cursorPos.floor() );
widget->setBorderWidth( PixelDensity::dpToPx( 2 ) );
widget->setPixelsSize( Sizef( getFontHeight(), getFontHeight() ) );
widget->setEnabled( false );
Float scale = eemax( getUISceneNode()->getPixelsSize().getWidth() / getFontHeight(),
getUISceneNode()->getPixelsSize().getHeight() / getFontHeight() );
widget->runAction( Actions::Sequence::New(
Actions::Scale::New( { scale, scale }, { 1, 1 }, Milliseconds( 250 ), Ease::Linear ),
Actions::Close::New() ) );
}
void UICodeEditor::setCodeEditorFlags( std::string flags, bool enable ) { void UICodeEditor::setCodeEditorFlags( std::string flags, bool enable ) {
String::toLowerInPlace( flags ); String::toLowerInPlace( flags );
String::readBySeparator( String::readBySeparator(
@@ -1302,22 +1280,6 @@ Uint32 UICodeEditor::onKeyDown( const KeyEvent& event ) {
} }
Uint32 UICodeEditor::onKeyUp( const KeyEvent& event ) { Uint32 UICodeEditor::onKeyUp( const KeyEvent& event ) {
if ( isEnabledFlashCursor() && event.getSanitizedMod() == KeyMod::getDefaultModifier() ) {
if ( mModDownCount == 0 )
mModDownClock.restart();
if ( mModDownClock.getElapsedTime() < Milliseconds( 250 ) ) {
mModDownCount++;
if ( mModDownCount == 5 ) {
mModDownCount = 0;
flashCursor();
}
} else
mModDownCount = 0;
mModDownClock.restart();
}
mLastActivity.restart(); mLastActivity.restart();
for ( auto& plugin : mPlugins ) for ( auto& plugin : mPlugins )
if ( plugin->onKeyUp( this, event ) ) if ( plugin->onKeyUp( this, event ) )
@@ -4428,7 +4390,6 @@ void UICodeEditor::registerCommands() {
mDoc->setCommand( "copy-file-path-and-position", [this] { copyFilePath( true ); } ); mDoc->setCommand( "copy-file-path-and-position", [this] { copyFilePath( true ); } );
mDoc->setCommand( "find-replace", [this] { showFindReplace(); } ); mDoc->setCommand( "find-replace", [this] { showFindReplace(); } );
mDoc->setCommand( "open-context-menu", [this] { createContextMenu(); } ); mDoc->setCommand( "open-context-menu", [this] { createContextMenu(); } );
mDoc->setCommand( "flash-cursor", [this] { flashCursor(); } );
mUnlockedCmd.insert( { "copy", "select-all", "open-containing-folder", mUnlockedCmd.insert( { "copy", "select-all", "open-containing-folder",
"copy-containing-folder-path", "copy-file-path", "copy-containing-folder-path", "copy-file-path",
"copy-file-path-and-position", "open-context-menu", "find-replace" } ); "copy-file-path-and-position", "open-context-menu", "find-replace" } );
+45 -7
View File
@@ -1329,13 +1329,29 @@ void UITabWidget::createTabSwitcher( const std::vector<Keycode>& tabSwitcherMeta
} }
} }
void UITabWidget::enableTabSwitcher( const std::vector<Keycode>& tabSwitcherMetaTrigger ) {
if ( !tabSwitcherMetaTrigger.empty() && !mTabSwitcherRunning ) {
mTabSwitcherRunning = true;
mFocusHistoryFreezed = mFocusHistory;
removeEventsOfType( Event::KeyUp );
on( Event::KeyUp, [this, tabSwitcherMetaTrigger]( const Event* event ) {
auto keyCode = event->asKeyEvent()->getKeyCode();
if ( std::find( tabSwitcherMetaTrigger.begin(), tabSwitcherMetaTrigger.end(),
keyCode ) != tabSwitcherMetaTrigger.end() ) {
removeEventListener( event->getCallbackId() );
mTabSwitcherRunning = false;
}
} );
}
}
void UITabWidget::focusNextTab( const std::vector<Keycode>& tabSwitcherMetaTrigger ) { void UITabWidget::focusNextTab( const std::vector<Keycode>& tabSwitcherMetaTrigger ) {
if ( mEnableTabSwitcher ) { if ( mEnableTabSwitcher ) {
bool wasVisible = mTabSwitcher && mTabSwitcher->isVisible(); bool wasEnabled = mTabSwitcher && mTabSwitcher->isVisible();
createTabSwitcher( tabSwitcherMetaTrigger ); createTabSwitcher( tabSwitcherMetaTrigger );
if ( wasVisible && !mTabSwitcher->getSelection().isEmpty() ) { if ( wasEnabled && !mTabSwitcher->getSelection().isEmpty() ) {
Int32 index = ( mTabSwitcher->getSelection().first().row() + 1 ) % Int32 index = ( mTabSwitcher->getSelection().first().row() + 1 ) %
mTabSwitcher->getModel()->rowCount(); mTabSwitcher->getModel()->rowCount();
mTabSwitcher->setSelection( mTabSwitcher->getModel()->index( index, 0 ) ); mTabSwitcher->setSelection( mTabSwitcher->getModel()->index( index, 0 ) );
@@ -1347,6 +1363,8 @@ void UITabWidget::focusNextTab( const std::vector<Keycode>& tabSwitcherMetaTrigg
if ( getTabCount() <= 1 ) if ( getTabCount() <= 1 )
return; return;
enableTabSwitcher( tabSwitcherMetaTrigger );
switch ( mTabJumpMode ) { switch ( mTabJumpMode ) {
case TabJumpMode::Linear: { case TabJumpMode::Linear: {
Int32 index = ( getTabSelectedIndex() + 1 ) % getTabCount(); Int32 index = ( getTabSelectedIndex() + 1 ) % getTabCount();
@@ -1354,9 +1372,14 @@ void UITabWidget::focusNextTab( const std::vector<Keycode>& tabSwitcherMetaTrigg
break; break;
} }
case TabJumpMode::Chronological: { case TabJumpMode::Chronological: {
Int32 newTabIndex = (Int32)getTabSelectedFocusHistoryIndex() - 1; if ( mTabSwitcherRunning ) {
Int32 index = newTabIndex < 0 ? mFocusHistory.size() - newTabIndex : newTabIndex; Int32 index =
setTabSelected( mFocusHistory[index] ); ( getTabSelectedFocusHistoryFreezedIndex() + 1 ) % mFocusHistory.size();
setTabSelected( mFocusHistoryFreezed[index] );
} else {
Int32 index = ( getTabSelectedFocusHistoryIndex() + 1 ) % mFocusHistory.size();
setTabSelected( mFocusHistory[index] );
}
break; break;
} }
} }
@@ -1380,6 +1403,8 @@ void UITabWidget::focusPreviousTab( const std::vector<Keycode>& tabSwitcherMetaT
if ( getTabCount() <= 1 ) if ( getTabCount() <= 1 )
return; return;
enableTabSwitcher( tabSwitcherMetaTrigger );
switch ( mTabJumpMode ) { switch ( mTabJumpMode ) {
case TabJumpMode::Linear: { case TabJumpMode::Linear: {
Int32 newTabIndex = (Int32)getTabSelectedIndex() - 1; Int32 newTabIndex = (Int32)getTabSelectedIndex() - 1;
@@ -1388,8 +1413,16 @@ void UITabWidget::focusPreviousTab( const std::vector<Keycode>& tabSwitcherMetaT
break; break;
} }
case TabJumpMode::Chronological: { case TabJumpMode::Chronological: {
Int32 index = ( getTabSelectedFocusHistoryIndex() + 1 ) % mFocusHistory.size(); if ( mTabSwitcherRunning ) {
setTabSelected( mFocusHistory[index] ); Int32 newTabIndex = (Int32)getTabSelectedFocusHistoryFreezedIndex() - 1;
Int32 index =
newTabIndex < 0 ? mFocusHistoryFreezed.size() + newTabIndex : newTabIndex;
setTabSelected( mFocusHistoryFreezed[index] );
} else {
Int32 newTabIndex = (Int32)getTabSelectedFocusHistoryIndex() - 1;
Int32 index = newTabIndex < 0 ? mFocusHistory.size() + newTabIndex : newTabIndex;
setTabSelected( mFocusHistory[index] );
}
break; break;
} }
} }
@@ -1400,4 +1433,9 @@ Uint32 UITabWidget::getTabSelectedFocusHistoryIndex() const {
return it != mFocusHistory.end() ? std::distance( mFocusHistory.begin(), it ) : 0; return it != mFocusHistory.end() ? std::distance( mFocusHistory.begin(), it ) : 0;
} }
Uint32 UITabWidget::getTabSelectedFocusHistoryFreezedIndex() const {
auto it = std::find( mFocusHistoryFreezed.begin(), mFocusHistoryFreezed.end(), mTabSelected );
return it != mFocusHistoryFreezed.end() ? std::distance( mFocusHistoryFreezed.begin(), it ) : 0;
}
}} // namespace EE::UI }} // namespace EE::UI
-2
View File
@@ -190,7 +190,6 @@ void AppConfig::load( const std::string& confPath, std::string& keybindingsPath,
editor.tabIndentAlignment = characterAlignmentFromString( editor.tabIndentAlignment = characterAlignmentFromString(
ini.getValue( "editor", "tab_indent_alignment", ini.getValue( "editor", "tab_indent_alignment",
characterAlignmentToString( CharacterAlignment::Center ) ) ); characterAlignmentToString( CharacterAlignment::Center ) ) );
editor.flashCursor = ini.getValueB( "editor", "flash_cursor", false );
searchBarConfig.caseSensitive = ini.getValueB( "search_bar", "case_sensitive", false ); searchBarConfig.caseSensitive = ini.getValueB( "search_bar", "case_sensitive", false );
searchBarConfig.luaPattern = ini.getValueB( "search_bar", "lua_pattern", false ); searchBarConfig.luaPattern = ini.getValueB( "search_bar", "lua_pattern", false );
@@ -344,7 +343,6 @@ void AppConfig::save( const std::vector<std::string>& recentFiles,
ini.setValue( "editor", "tab_indent_character", editor.tabIndentCharacter ); ini.setValue( "editor", "tab_indent_character", editor.tabIndentCharacter );
ini.setValue( "editor", "tab_indent_alignment", ini.setValue( "editor", "tab_indent_alignment",
characterAlignmentToString( editor.tabIndentAlignment ) ); characterAlignmentToString( editor.tabIndentAlignment ) );
ini.setValueB( "editor", "flash_cursor", editor.flashCursor );
ini.setValueB( "search_bar", "case_sensitive", searchBarConfig.caseSensitive ); ini.setValueB( "search_bar", "case_sensitive", searchBarConfig.caseSensitive );
ini.setValueB( "search_bar", "lua_pattern", searchBarConfig.luaPattern ); ini.setValueB( "search_bar", "lua_pattern", searchBarConfig.luaPattern );
-1
View File
@@ -85,7 +85,6 @@ struct CodeEditorConfig {
bool autoReloadOnDiskChange{ false }; bool autoReloadOnDiskChange{ false };
bool codeFoldingEnabled{ true }; bool codeFoldingEnabled{ true };
bool codeFoldingAlwaysVisible{ false }; bool codeFoldingAlwaysVisible{ false };
bool flashCursor{ false };
LineWrapMode wrapMode{ LineWrapMode::NoWrap }; LineWrapMode wrapMode{ LineWrapMode::NoWrap };
LineWrapType wrapType{ LineWrapType::Viewport }; LineWrapType wrapType{ LineWrapType::Viewport };
bool wrapKeepIndentation{ true }; bool wrapKeepIndentation{ true };
-1
View File
@@ -2375,7 +2375,6 @@ void App::onCodeEditorCreated( UICodeEditor* editor, TextDocument& doc ) {
editor->setLineWrapType( config.wrapType ); editor->setLineWrapType( config.wrapType );
editor->setFoldDrawable( findIcon( "chevron-down", PixelDensity::dpToPxI( 12 ) ) ); editor->setFoldDrawable( findIcon( "chevron-down", PixelDensity::dpToPxI( 12 ) ) );
editor->setFoldedDrawable( findIcon( "chevron-right", PixelDensity::dpToPxI( 12 ) ) ); editor->setFoldedDrawable( findIcon( "chevron-right", PixelDensity::dpToPxI( 12 ) ) );
editor->setEnableFlashCursor( config.flashCursor );
editor->setTabStops( mConfig.doc.tabStops ); editor->setTabStops( mConfig.doc.tabStops );
doc.setAutoCloseBrackets( !mConfig.editor.autoCloseBrackets.empty() ); doc.setAutoCloseBrackets( !mConfig.editor.autoCloseBrackets.empty() );
-16
View File
@@ -671,17 +671,6 @@ UIMenu* SettingsMenu::createDocumentMenu() {
"before exiting the program." ) ) "before exiting the program." ) )
->setId( "session_snapshot" ); ->setId( "session_snapshot" );
mGlobalMenu
->addCheckBox( i18n( "allow_flash_cursor", "Allow Flashing Cursor" ),
mApp->getConfig().editor.flashCursor )
->setTooltipText( i18n(
"allow_flash_cursor_desc",
"When enabled, pressing the default modifier key 5 times within 1.5 seconds will\n"
"trigger a visual effect that highlights the current cursor position. A large,\n"
"transparent rectangle will briefly animate, shrinking down to the cursor, making it\n"
"easier to locate when it's hard to see." ) )
->setId( "allow_flash_cursor" );
mGlobalMenu->addSeparator(); mGlobalMenu->addSeparator();
mGlobalMenu->add( i18n( "line_breaking_column", "Line Breaking Column" ) ) mGlobalMenu->add( i18n( "line_breaking_column", "Line Breaking Column" ) )
@@ -740,11 +729,6 @@ UIMenu* SettingsMenu::createDocumentMenu() {
mApp->getConfig().editor.autoReloadOnDiskChange = item->isActive(); mApp->getConfig().editor.autoReloadOnDiskChange = item->isActive();
} else if ( "session_snapshot" == id ) { } else if ( "session_snapshot" == id ) {
mApp->getConfig().workspace.sessionSnapshot = item->isActive(); mApp->getConfig().workspace.sessionSnapshot = item->isActive();
} else if ( "allow_flash_cursor" == id ) {
mApp->getConfig().editor.flashCursor = item->isActive();
mSplitter->forEachEditor( [this]( UICodeEditor* editor ) {
editor->setEnableFlashCursor( mApp->getConfig().editor.flashCursor );
} );
} else if ( "tab_stops" == id ) { } else if ( "tab_stops" == id ) {
mApp->getConfig().doc.tabStops = item->isActive(); mApp->getConfig().doc.tabStops = item->isActive();
mSplitter->forEachEditor( [this]( UICodeEditor* editor ) { mSplitter->forEachEditor( [this]( UICodeEditor* editor ) {