Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions TeXmacs/progs/generic/format-edit.scm
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,22 @@
(tm-define (toggle-underlined)
(toggle-with-like '(underline "") #f))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Predicates for toolbar button state synchronization
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(tm-define (inside-bold?)
(== (get-env "font-series") "bold"))

(tm-define (inside-italic?)
(== (get-env "font-shape") "italic"))

(tm-define (inside-underline?)
(not (not (tree-innermost 'underline #t))))

(tm-define (inside-strike-through?)
(not (not (tree-innermost 'strike-through #t))))

(tm-define (make-alternate prompt default-val tag)
(:interactive #t)
(interactive (lambda (x) (make-with-like `(,tag ,x "")))
Expand Down
16 changes: 10 additions & 6 deletions TeXmacs/progs/text/text-menu.scm
Original file line number Diff line number Diff line change
Expand Up @@ -636,13 +636,17 @@
;;(text (roman rm bold right 12 600) "S")
;;"Write bold text")
;;(make-with "font-series" "bold"))
((balloon (icon "tm_bold.xpm") "Write bold text")
(toggle-bold))
((balloon (icon "tm_italic.xpm") "Write italic text")
(toggle-italic))
((balloon (icon "tm_underline.xpm") "Write underline")
((check (balloon (icon "tm_bold.xpm") "Write bold text")
"v" (inside-bold?))
(make-with "font-series" "bold"))
((check (balloon (icon "tm_italic.xpm") "Write italic text")
"v" (inside-italic?))
(make-with "font-shape" "italic"))
((check (balloon (icon "tm_underline.xpm") "Write underline")
"v" (inside-underline?))
(make 'underline))
((balloon (icon "tm_strikethrough.xpm") "Write strike through")
((check (balloon (icon "tm_strikethrough.xpm") "Write strike through")
"v" (inside-strike-through?))
(make 'strike-through))
((balloon (icon "tm_marked.svg") "Marked text")
(mark-text)))
Expand Down
46 changes: 46 additions & 0 deletions devel/202_107.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# #2903 Toolbar formatting buttons should reflect the current formatting state

### How to test
1. Open Mogan and create a new document
2. Type some text, then select a portion and click the **Bold** toolbar button
3. Move the cursor inside the bold text. Verify the Bold button appears pressed/highlighted
4. Move the cursor outside the bold text. Verify the Bold button returns to normal
5. Repeat steps 2–4 for Italic, Underline, and Strikethrough buttons

## 2026/03/01
### What
Added state synchronization between the toolbar formatting buttons (Bold, Italic, Underline, Strikethrough) and the editor's document model. When the cursor is inside formatted text, the corresponding toolbar button now appears pressed/highlighted.

### Why
Previously, the Bold, Underline, and similar buttons behaved like simple action triggers: when clicked, they executed a formatting command and immediately returned to their default visual state. This made them functionally correct but visually misleading, because the user received no persistent feedback indicating whether the current cursor position was inside formatted text.

A well-designed text editor treats these buttons as reflections of the editor's current formatting context. The toolbar should derive its visual state directly from the document model, the single source of truth. This aligns the behavior with professional editors like Word or Google Docs.

### How
Two Scheme files were modified. No C++ changes were needed.

In `TeXmacs/progs/generic/format-edit.scm`, added four predicates that query the current formatting state at the cursor:

```scheme
(tm-define (inside-bold?)
(== (get-env "font-series") "bold"))

(tm-define (inside-italic?)
(== (get-env "font-shape") "italic"))

(tm-define (inside-underline?)
(not (not (tree-innermost 'underline #t))))

(tm-define (inside-strike-through?)
(not (not (tree-innermost 'strike-through #t))))
```

In `TeXmacs/progs/text/text-menu.scm`, wrapped each formatting button in `text-format-icons` with the existing `check` macro, passing the corresponding predicate:

```scheme
((check (balloon (icon "tm_bold.xpm") "Write bold text")
"v" (inside-bold?))
(make-with "font-series" "bold"))
```

The `check` macro re-evaluates the predicate on every toolbar refresh (triggered by cursor movement and context changes). If `#t`, the button appears pressed via `WIDGET_STYLE_PRESSED`.