You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add a contextual menu (right-click) directly on the StyleClassedTextArea editor field inside DocumentTab.
The menu must reflect the common Markdown formatting actions and provide keyboard shortcut equivalents.
Attachment: editor.setContextMenu(createEditorContextMenu()) — same pattern as ProjectExplorerPanel.createContextMenu().
Keyboard shortcuts: extend the existing editor.setOnKeyPressed(...) handler (currently handling Ctrl+F and Ctrl+H).
Menu structure
Copy Ctrl+C
Cut Ctrl+X
Paste Ctrl+V
──────────────────────
Title H1 Ctrl+1
Title H2 Ctrl+2
Title H3 Ctrl+3
Title H4 Ctrl+4
Title H5 Ctrl+5
Title H6 Ctrl+6
──────────────────────
Bold Ctrl+B
Italic Ctrl+I
──────────────────────
Insert link Ctrl+K
Insert image Ctrl+J
Behaviour per entry
Copy / Cut / Paste
Delegate directly to editor.copy(), editor.cut(), editor.paste().
These are standard JavaFX clipboard operations — no custom logic required.
Keyboard shortcuts: OS-native (Ctrl+C, Ctrl+X, Ctrl+V) are already handled by RichTextFX; the menu items only need to call the API methods.
Title H1 – H6 (Ctrl+1 … Ctrl+6)
Act on the current line (no selection required).
Algorithm:
Retrieve the paragraph index at the caret: editor.getCurrentParagraph().
Get the current paragraph text: editor.getParagraph(idx).getText().
Strip any existing leading # characters and the optional trailing space.
Prepend the appropriate prefix (#, ##, … ######) followed by a space.
Replace the paragraph in-place using editor.replaceText(start, end, newLine).
If the line already has the same heading level, toggle it off (remove the prefix).
Bold (Ctrl+B)
Requires a non-empty selection.
Wrap the selected text: **<SELECTION>**.
Place the caret at the end of the wrapped text after insertion.
If the selection is already surrounded by **, unwrap it instead (toggle behaviour).
Item is disabled in the context menu when editor.getSelection().getLength() == 0.
Italic (Ctrl+I)
Same toggle logic as Bold, using single asterisks: *<SELECTION>*.
Item is disabled when no text is selected.
Insert link (Ctrl+K)
Requires a non-empty selection which becomes the URL part of the link.
Inserts: [<CURSOR>](<TEXT_SELECTED>) where <CURSOR> marks where the caret lands after insertion (i.e., between [ and ]).
Concrete steps:
Read String url = editor.getSelectedText().
Replace selection with "[]("+url+")".
Move caret to position selectionStart + 1 (inside the brackets).
Item is disabled when no text is selected.
Warning
Keyboard conflict: Ctrl+H is already bound in DocumentTab to open the Search & Replace bar (searchReplaceBar.showSearchAndReplace()).
The original spec proposed Ctrl+H for Insert link — this would break the search feature. Decision: use Ctrl+K for Insert link (consistent with VS Code, IntelliJ, Typora).
The Ctrl+H binding for Search & Replace is kept unchanged.
Insert image (Ctrl+J)
Same logic as Insert link but with the image syntax.
Inserts:  — caret lands at position selectionStart + 2 (inside ![ … ]).
Item is disabled when no text is selected.
Conditional item enabling
Set the menu's onShowing handler to enable/disable items depending on context:
contextMenu.setOnShowing(e -> {
booleanhasSelection = editor.getSelection().getLength() > 0;
boldItem.setDisable(!hasSelection);
italicItem.setDisable(!hasSelection);
insertLinkItem.setDisable(!hasSelection);
insertImageItem.setDisable(!hasSelection);
// Copy/Cut also require a selectioncopyItem.setDisable(!hasSelection);
cutItem.setDisable(!hasSelection);
});
Internationalisation
Add the following keys to every messages_*.properties file:
In a subsequent iteration, a floating toolbar will appear above the selection whenever the user selects text in the editor.
It will expose the same formatting actions (Bold, Italic, Insert link, Insert image, heading level picker) as icon buttons or a combo-box, without requiring the context menu.
Implementation hint: listen to editor.selectedTextProperty() changes; when selection becomes non-empty, compute the screen coordinates of the selection start via editor.getCharacterBoundsOnScreen(start, end) and position a Popup node accordingly.
Editor Context Menu
Goal
Add a contextual menu (right-click) directly on the
StyleClassedTextArea editorfield insideDocumentTab.The menu must reflect the common Markdown formatting actions and provide keyboard shortcut equivalents.
Implementation location
ui/DocumentTab.javaStyleClassedTextArea editor(RichTextFX)editor.setContextMenu(createEditorContextMenu())— same pattern asProjectExplorerPanel.createContextMenu().editor.setOnKeyPressed(...)handler (currently handlingCtrl+FandCtrl+H).Menu structure
Behaviour per entry
Copy / Cut / Paste
editor.copy(),editor.cut(),editor.paste().Ctrl+C,Ctrl+X,Ctrl+V) are already handled by RichTextFX; the menu items only need to call the API methods.Title H1 – H6 (
Ctrl+1…Ctrl+6)editor.getCurrentParagraph().editor.getParagraph(idx).getText().#characters and the optional trailing space.#,##, …######) followed by a space.editor.replaceText(start, end, newLine).Bold (
Ctrl+B)**<SELECTION>**.**, unwrap it instead (toggle behaviour).editor.getSelection().getLength() == 0.Italic (
Ctrl+I)*<SELECTION>*.Insert link (
Ctrl+K)[<CURSOR>](<TEXT_SELECTED>)where<CURSOR>marks where the caret lands after insertion (i.e., between[and]).String url = editor.getSelectedText()."[]("+url+")".selectionStart + 1(inside the brackets).Warning
Keyboard conflict:
Ctrl+His already bound inDocumentTabto open the Search & Replace bar (searchReplaceBar.showSearchAndReplace()).The original spec proposed
Ctrl+Hfor Insert link — this would break the search feature.Decision: use
Ctrl+Kfor Insert link (consistent with VS Code, IntelliJ, Typora).The
Ctrl+Hbinding for Search & Replace is kept unchanged.Insert image (
Ctrl+J)— caret lands at positionselectionStart + 2(inside![…]).Conditional item enabling
Set the menu's
onShowinghandler to enable/disable items depending on context:Internationalisation
Add the following keys to every
messages_*.propertiesfile:Floating toolbar (later)
Note
In a subsequent iteration, a floating toolbar will appear above the selection whenever the user selects text in the editor.
It will expose the same formatting actions (Bold, Italic, Insert link, Insert image, heading level picker) as icon buttons or a combo-box, without requiring the context menu.
Implementation hint: listen to
editor.selectedTextProperty()changes; when selection becomes non-empty, compute the screen coordinates of the selection start viaeditor.getCharacterBoundsOnScreen(start, end)and position aPopupnode accordingly.