From 041d5d4305c13d82dc98d83bdc055544214bfeff Mon Sep 17 00:00:00 2001 From: scheffle Date: Thu, 12 Dec 2024 14:30:52 +0100 Subject: [PATCH 1/2] fix selecting text with tab stops --- vstgui/lib/ctexteditor.cpp | 36 +++++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/vstgui/lib/ctexteditor.cpp b/vstgui/lib/ctexteditor.cpp index 29f60abea..9a5fe86f3 100644 --- a/vstgui/lib/ctexteditor.cpp +++ b/vstgui/lib/ctexteditor.cpp @@ -117,10 +117,11 @@ inline Range makeRange (const STB_TexteditState& state) } //------------------------------------------------------------------------ -inline void replaceTabs (std::string& str, uint32_t tabWidth, size_t lineOffset) +inline size_t replaceTabs (std::string& str, uint32_t tabWidth, size_t lineOffset) { if (tabWidth < 1) - return; + return 0; + auto numReplacedChars = 0u; auto whiteSpace = ' '; std::string::size_type pos = std::string::npos; while ((pos = str.find_first_of ('\t')) != std::string::npos) @@ -128,7 +129,9 @@ inline void replaceTabs (std::string& str, uint32_t tabWidth, size_t lineOffset) auto numWhiteSpace = tabWidth - ((pos + lineOffset) % tabWidth); std::string s (numWhiteSpace, whiteSpace); str.replace (pos, 1, s); + numReplacedChars += numWhiteSpace - 1; } + return numReplacedChars; } //------------------------------------------------------------------------ @@ -999,12 +1002,14 @@ void TextEditorView::drawRect (CDrawContext* context, const CRect& dirtyRect) toLineSelection (line.range, md.editState.select_start, md.editState.select_end); if (selRange) { + size_t selOffset = static_cast (selRange.start); auto selX = x; if (selRange.start != 0) { auto t = md.model.text.substr (line.range.start, selRange.start); auto nonSelectedText = convert (t); - replaceTabs (nonSelectedText, md.style->tabWidth, 0u); + selOffset += replaceTabs (nonSelectedText, md.style->tabWidth, 0u); + // selOffset -= selOffset / md.style->tabWidth; selX += context->getStringWidth (nonSelectedText.data ()); } CRect r (selX, y - md.fontAscent, selX, y + md.fontDescent); @@ -1015,8 +1020,7 @@ void TextEditorView::drawRect (CDrawContext* context, const CRect& dirtyRect) { auto t = md.model.text.substr (line.range.start + selRange.start, selRange.length); auto selectedText = convert (t); - replaceTabs (selectedText, md.style->tabWidth, - static_cast (selRange.start - line.range.start)); + replaceTabs (selectedText, md.style->tabWidth, selOffset); r.setWidth (context->getStringWidth (selectedText.data ())); } r.inset (0, -md.style->lineSpacing / 2.); @@ -1812,13 +1816,23 @@ float TextEditorView::getCharWidth (size_t row, size_t pos) const UTF8String str (convert (&c, 1)); if (str[0] == '\n') return STB_TEXTEDIT_GETWIDTH_NEWLINE; - bool isTab = str[0] == '\t'; - if (isTab && md.style->tabWidth > 0) + + if (md.style->tabWidth > 0 && str[0] == '\t') { - str = " "; - auto tabWidth = md.style->tabWidth; - while (--tabWidth) - str += " "; + auto posOffset = 0; + auto numTabs = 0u; + size_t numSpaces = md.style->tabWidth; + for (auto index = 0u; index <= pos; ++index) + { + if (md.model.text[row + index] == '\t') + { + numSpaces = + md.style->tabWidth - (((index - numTabs) + posOffset) % md.style->tabWidth); + posOffset += numSpaces; + ++numTabs; + } + } + str = std::string (numSpaces, ' '); } auto width = fontPainter->getStringWidth (nullptr, str.getPlatformString (), true); return static_cast (width / getGlobalTransform (true).m11); From 709def98cd6f2b5ef9a5a34a290f2c1b59cce29e Mon Sep 17 00:00:00 2001 From: scheffle Date: Thu, 12 Dec 2024 14:43:14 +0100 Subject: [PATCH 2/2] update github actions macos environments --- .github/workflows/cmake_macos.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/cmake_macos.yml b/.github/workflows/cmake_macos.yml index 5fe120fd7..f53b2bb66 100644 --- a/.github/workflows/cmake_macos.yml +++ b/.github/workflows/cmake_macos.yml @@ -8,7 +8,7 @@ jobs: strategy: matrix: - os: [macos-12, macos-14] + os: [macos-13, macos-14, macos-15] steps: - uses: actions/checkout@v4