From 7b6e0638f69bf49ed51c37a64e7027eceafb0123 Mon Sep 17 00:00:00 2001 From: Chris Roberts Date: Mon, 9 Feb 2026 19:39:57 -0700 Subject: [PATCH] add variable width cursor support --- locales/en.catkeys | 5 ++-- src/editor/EditorWindow.cpp | 8 ++++-- src/preferences/AppPreferencesWindow.cpp | 35 +++++++++++++++++++++--- src/preferences/AppPreferencesWindow.h | 3 +- src/preferences/Preferences.cpp | 6 ++-- src/preferences/Preferences.h | 2 +- 6 files changed, 46 insertions(+), 13 deletions(-) diff --git a/locales/en.catkeys b/locales/en.catkeys index afbf10e..781225e 100644 --- a/locales/en.catkeys +++ b/locales/en.catkeys @@ -1,4 +1,4 @@ -1 English x-vnd.KapiX-Koder 4193593144 +1 English x-vnd.KapiX-Koder 771836523 Something wrong has happened while opening the configuration file. Your personal settings will not be %s%. Preferences Something wrong has happened while opening the configuration file. Your personal settings will not be %s%. Access denied EditorWindow Access denied Line endings EditorWindow Line endings @@ -50,6 +50,7 @@ Match case FindWindow Match case Distributed on MIT license terms. App Distributed on MIT license terms. Couldn't find style files. Make sure you have them installed in one of your data directories. Styler Couldn't find style files. Make sure you have them installed in one of your data directories. Find: FindWindow Find: +Block AppPreferencesWindow Cursor width or style Block View EditorWindow View Neil Hodgson, for Scintilla editing component and SciTE editor. App Neil Hodgson, for Scintilla editing component and SciTE editor. Reached the end of the target. No results found. EditorWindow Reached the end of the target. No results found. @@ -155,6 +156,7 @@ Preferences… EditorWindow Preferences… Go to line GoToLineWindow Go to line Reload EditorWindow Reload There are unsaved changes.\nSelect the files to save. QuitAlert There are unsaved changes.\nSelect the files to save. +Cursor width (pixels) AppPreferencesWindow Cursor width (pixels) The file has been removed. What to do? EditorWindow The file has been removed. What to do? Enormous AppPreferencesWindow Toolbar icon size Enormous Trim trailing whitespace EditorWindow Trim trailing whitespace @@ -176,7 +178,6 @@ File modified EditorWindow File modified Highlight braces AppPreferencesWindow Highlight braces Save selected QuitAlert Save selected Max. characters per line: AppPreferencesWindow Max. characters per line: -Use block cursor AppPreferencesWindow Use block cursor Highlight trailing whitespace AppPreferencesWindow Highlight trailing whitespace Up to the next/previous non-empty line AppPreferencesWindow Up to the next/previous non-empty line Show indentation guides AppPreferencesWindow Show indentation guides diff --git a/src/editor/EditorWindow.cpp b/src/editor/EditorWindow.cpp index efcbf9a..67a2f47 100644 --- a/src/editor/EditorWindow.cpp +++ b/src/editor/EditorWindow.cpp @@ -1331,8 +1331,12 @@ EditorWindow::_SyncWithPreferences() fEditor->SendMessage(SCI_SETCARETLINEVISIBLE, fPreferences->fLineHighlighting, 0); fEditor->SendMessage(SCI_SETCARETLINEVISIBLEALWAYS, true, 0); fEditor->SendMessage(SCI_SETCARETLINEFRAME, fPreferences->fLineHighlightingMode ? 2 : 0); - fEditor->SendMessage(SCI_SETCARETSTYLE, - fPreferences->fUseBlockCursor ? (CARETSTYLE_BLOCK | CARETSTYLE_BLOCK_AFTER) : CARETSTYLE_LINE); + if(fPreferences->fCursorWidth == UINT8_MAX) { + fEditor->SendMessage(SCI_SETCARETSTYLE, (CARETSTYLE_BLOCK | CARETSTYLE_BLOCK_AFTER)); + } else { + fEditor->SendMessage(SCI_SETCARETSTYLE, CARETSTYLE_LINE); + fEditor->SendMessage(SCI_SETCARETWIDTH, fPreferences->fCursorWidth); + } if(fFilePreferences.fEOLMode) { fEditor->SendMessage(SCI_SETEOLMODE, fFilePreferences.fEOLMode.value_or(SC_EOL_LF), 0); diff --git a/src/preferences/AppPreferencesWindow.cpp b/src/preferences/AppPreferencesWindow.cpp index c5b6001..6b3b036 100644 --- a/src/preferences/AppPreferencesWindow.cpp +++ b/src/preferences/AppPreferencesWindow.cpp @@ -160,8 +160,12 @@ AppPreferencesWindow::MessageReceived(BMessage* message) fPreferences->fBracesHighlighting = IsChecked(fBracesHighlightingCB); _PreferencesModified(); } break; + case Actions::CURSOR_WIDTH: { + fPreferences->fCursorWidth = std::stoi(fCursorWidthMF->Menu()->FindMarked()->Label()); + _PreferencesModified(); + } break; case Actions::BLOCK_CURSOR: { - fPreferences->fUseBlockCursor = IsChecked(fBlockCursorCB); + fPreferences->fCursorWidth = UINT8_MAX; _PreferencesModified(); } break; case Actions::EDITOR_STYLE: { @@ -341,7 +345,18 @@ AppPreferencesWindow::_InitInterface() fIndentGuidesBox->SetLabel(fIndentGuidesShowCB); fBracesHighlightingCB = new BCheckBox("bracesHighlighting", B_TRANSLATE("Highlight braces"), new BMessage((uint32) Actions::BRACES_HIGHLIGHTING)); - fBlockCursorCB = new BCheckBox("blockCursor", B_TRANSLATE("Use block cursor"), new BMessage((uint32) Actions::BLOCK_CURSOR)); + + BPopUpMenu* cursorMenu = new BPopUpMenu("cursorMenu"); + auto menuBuilder = BLayoutBuilder::Menu<>(cursorMenu); + for(int32 x = 1; x < 6; x++) { + BString label; + label << x; + menuBuilder.AddItem(label.String(), CURSOR_WIDTH); + } + menuBuilder + .AddSeparator() + .AddItem(B_TRANSLATE_COMMENT("Block", "Cursor width or style"), BLOCK_CURSOR); + fCursorWidthMF = new BMenuField("cursorWidth", B_TRANSLATE("Cursor width (pixels)"), cursorMenu); fEditorStyleMenu = new BPopUpMenu("style"); fEditorStyleMF = new BMenuField("style", B_TRANSLATE("Style"), fEditorStyleMenu); @@ -380,7 +395,7 @@ AppPreferencesWindow::_InitInterface() .Add(fCompactLangMenuCB) .Add(fFullPathInTitleCB) .Add(fBracesHighlightingCB) - .Add(fBlockCursorCB) + .Add(fCursorWidthMF) .Add(fToolbarBox) .AddStrut(B_USE_HALF_ITEM_SPACING) .Add(fLineLimitBox) @@ -485,8 +500,20 @@ AppPreferencesWindow::_SyncPreferences(Preferences* preferences) fFontSizeSpinner->SetMessage(new BMessage((uint32) Actions::FONT_SIZE_CHANGED)); _UpdateFontMenu(); + BMenu* cursorMenu = fCursorWidthMF->Menu(); + BMenuItem* cursorItem = nullptr; + if(preferences->fCursorWidth == UINT8_MAX) { + cursorItem = cursorMenu->FindItem(BLOCK_CURSOR); + } else { + BString label; + label << preferences->fCursorWidth; + cursorItem = cursorMenu->FindItem(label.String()); + } + if(cursorItem != nullptr) { + cursorItem->SetMarked(true); + } + SetChecked(fBracesHighlightingCB, preferences->fBracesHighlighting); - SetChecked(fBlockCursorCB, preferences->fUseBlockCursor); SetChecked(fAttachNewWindowsCB, preferences->fOpenWindowsInStack); SetChecked(fHighlightTrailingWSCB, preferences->fHighlightTrailingWhitespace); SetChecked(fTrimTrailingWSOnSaveCB, preferences->fTrimTrailingWhitespaceOnSave); diff --git a/src/preferences/AppPreferencesWindow.h b/src/preferences/AppPreferencesWindow.h index 64eb9e3..af8e69a 100644 --- a/src/preferences/AppPreferencesWindow.h +++ b/src/preferences/AppPreferencesWindow.h @@ -42,6 +42,7 @@ class AppPreferencesWindow : public BWindow { TOOLBAR = 'tlbr', TOOLBAR_ICON_SIZE = 'tlis', FULL_PATH_IN_TITLE = 'fpit', + CURSOR_WIDTH = 'crwd', BLOCK_CURSOR = 'bloc', TABS_TO_SPACES = 'ttsp', TAB_WIDTH = 'tbwd', @@ -137,7 +138,7 @@ class AppPreferencesWindow : public BWindow { BRadioButton* fIndentGuidesLookBothRadio; BCheckBox* fBracesHighlightingCB; - BCheckBox* fBlockCursorCB; + BMenuField* fCursorWidthMF; BPopUpMenu* fEditorStyleMenu; BMenuField* fEditorStyleMF; diff --git a/src/preferences/Preferences.cpp b/src/preferences/Preferences.cpp index 3589c3f..27b5d1b 100644 --- a/src/preferences/Preferences.cpp +++ b/src/preferences/Preferences.cpp @@ -103,7 +103,7 @@ Preferences::Load(const char* filename) fLineLimitColumn = storage.GetUInt32("lineLimitColumn", 80); fWrapLines = storage.GetBool("wrapLines", false); fBracesHighlighting = storage.GetBool("bracesHighlighting", true); - fUseBlockCursor = storage.GetBool("useBlockCursor", false); + fCursorWidth = storage.GetUInt8("cursorWidth", 1); fFullPathInTitle = storage.GetBool("fullPathInTitle", true); fCompactLangMenu = storage.GetBool("compactLangMenu", true); fToolbar = storage.GetBool("toolbar", true); @@ -148,7 +148,7 @@ Preferences::Save(const char* filename) storage.AddUInt32("lineLimitColumn", fLineLimitColumn); storage.AddBool("wrapLines", fWrapLines); storage.AddBool("bracesHighlighting", fBracesHighlighting); - storage.AddBool("useBlockCursor", fUseBlockCursor); + storage.AddUInt8("cursorWidth", fCursorWidth); storage.AddBool("fullPathInTitle", fFullPathInTitle); storage.AddBool("compactLangMenu", fCompactLangMenu); storage.AddBool("toolbar", fToolbar); @@ -193,7 +193,7 @@ Preferences::operator =(Preferences& p) fLineLimitColumn = p.fLineLimitColumn; fWrapLines = p.fWrapLines; fBracesHighlighting = p.fBracesHighlighting; - fUseBlockCursor = p.fUseBlockCursor; + fCursorWidth = p.fCursorWidth; fFullPathInTitle = p.fFullPathInTitle; fCompactLangMenu = p.fCompactLangMenu; fToolbar = p.fToolbar; diff --git a/src/preferences/Preferences.h b/src/preferences/Preferences.h index b6ded97..0f8f5ae 100644 --- a/src/preferences/Preferences.h +++ b/src/preferences/Preferences.h @@ -48,7 +48,7 @@ class Preferences { uint32 fLineLimitColumn; bool fWrapLines; bool fBracesHighlighting; - bool fUseBlockCursor; + uint8 fCursorWidth; bool fFullPathInTitle; bool fCompactLangMenu; bool fToolbar;