Skip to content

Commit 67ca3b4

Browse files
committed
Added configuration for displaying tabs and spaces separately (BalazsJako#31)
1 parent f76e87d commit 67ca3b4

5 files changed

Lines changed: 15 additions & 8 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public API to externally implement these features is however included.
8686
- Has API to filter each line in editor (with full undo support).
8787
- Tabs to Space (and visa versa) are examples of line filtering.
8888
- Has API to strip trailing whitespaces.
89-
- Provides whitespace indicators for tabs and spaces (can be turned on and off).
89+
- Provides whitespace indicators for tabs and spaces (can be turned on and off individually or collectively).
9090
- No longer uses regular expressions for colorizing text (see below).
9191
- Provides an optional companion widget to show source code differences between versions (see below).
9292

TextDiff.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ void TextDiff::renderSideBySideLine(float x, float y, TextEditor::Line& line) {
403403
ImVec2 glyphPos(x + column * glyphSize.x - textScroll, y);
404404

405405
if (codepoint == '\t') {
406-
if (showWhitespaces) {
406+
if (showTabs) {
407407
const auto x1 = glyphPos.x + glyphSize.x * 0.3f;
408408
const auto y1 = glyphPos.y + fontSize * 0.5f;
409409
const auto x2 = glyphPos.x + glyphSize.x;
@@ -420,7 +420,7 @@ void TextDiff::renderSideBySideLine(float x, float y, TextEditor::Line& line) {
420420
}
421421

422422
} else if (codepoint == ' ') {
423-
if (showWhitespaces) {
423+
if (showSpaces) {
424424
const auto x1 = glyphPos.x + glyphSize.x * 0.5f;
425425
const auto y1 = glyphPos.y + fontSize * 0.5f;
426426
drawList->AddCircleFilled(ImVec2(x1, y1), 1.5f, palette.get(Color::whitespace), 4);

TextEditor.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ void TextEditor::renderText() {
390390
ImVec2 glyphPos{lineScreenPos.x + column * glyphSize.x, lineScreenPos.y};
391391

392392
if (codepoint == '\t') {
393-
if (showWhitespaces) {
393+
if (showTabs) {
394394
const auto x1 = glyphPos.x + glyphSize.x * 0.3f;
395395
const auto y = glyphPos.y + fontSize * 0.5f;
396396
const auto x2 = glyphPos.x + glyphSize.x;
@@ -407,7 +407,7 @@ void TextEditor::renderText() {
407407
}
408408

409409
} else if (codepoint == ' ') {
410-
if (showWhitespaces) {
410+
if (showSpaces) {
411411
const auto x = glyphPos.x + glyphSize.x * 0.5f;
412412
const auto y = glyphPos.y + fontSize * 0.5f;
413413
drawList->AddCircleFilled(ImVec2(x, y), 1.5f, palette.get(Color::whitespace), 4);

TextEditor.h

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,12 @@ class TextEditor {
5656
inline bool IsReadOnlyEnabled() const { return readOnly; }
5757
inline void SetAutoIndentEnabled(bool value) { autoIndent = value; }
5858
inline bool IsAutoIndentEnabled() const { return autoIndent; }
59-
inline void SetShowWhitespacesEnabled(bool value) { showWhitespaces = value; }
60-
inline bool IsShowWhitespacesEnabled() const { return showWhitespaces; }
59+
inline void SetShowWhitespacesEnabled(bool value) { showSpaces = value; showTabs = value; }
60+
inline bool IsShowWhitespacesEnabled() const { return showSpaces && showTabs; }
61+
inline void SetShowSpacesEnabled(bool value) { showSpaces = value; }
62+
inline bool IsShowSpacesEnabled() const { return showSpaces; }
63+
inline void SetShowTabsEnabled(bool value) { showTabs = value; }
64+
inline bool IsShowTabsEnabled() const { return showTabs; }
6165
inline void SetShowLineNumbersEnabled(bool value) { showLineNumbers = value; }
6266
inline bool IsShowLineNumbersEnabled() const { return showLineNumbers; }
6367
inline void SetShowScrollbarMiniMapEnabled(bool value) { showScrollbarMiniMap = value; }
@@ -1032,7 +1036,8 @@ class TextEditor {
10321036
float lineSpacing = 1.0f;
10331037
bool readOnly = false;
10341038
bool autoIndent = true;
1035-
bool showWhitespaces = true;
1039+
bool showSpaces = true;
1040+
bool showTabs = true;
10361041
bool showLineNumbers = true;
10371042
bool showScrollbarMiniMap = true;
10381043
bool showMatchingBrackets = true;

example/editor.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,8 @@ void Editor::renderMenuBar() {
280280

281281
bool flag;
282282
flag = editor.IsShowWhitespacesEnabled(); if (ImGui::MenuItem("Show Whitespaces", nullptr, &flag)) { editor.SetShowWhitespacesEnabled(flag); };
283+
flag = editor.IsShowSpacesEnabled(); if (ImGui::MenuItem("Show Spaces", nullptr, &flag)) { editor.SetShowSpacesEnabled(flag); };
284+
flag = editor.IsShowTabsEnabled(); if (ImGui::MenuItem("Show Tabs", nullptr, &flag)) { editor.SetShowTabsEnabled(flag); };
283285
flag = editor.IsShowLineNumbersEnabled(); if (ImGui::MenuItem("Show Line Numbers", nullptr, &flag)) { editor.SetShowLineNumbersEnabled(flag); };
284286
flag = editor.IsShowingMatchingBrackets(); if (ImGui::MenuItem("Show Matching Brackets", nullptr, &flag)) { editor.SetShowMatchingBrackets(flag); };
285287
flag = editor.IsCompletingPairedGlyphs(); if (ImGui::MenuItem("Complete Matching Glyphs", nullptr, &flag)) { editor.SetCompletePairedGlyphs(flag); };

0 commit comments

Comments
 (0)