Markpad icon indicating copy to clipboard operation
Markpad copied to clipboard

Monaco's default options were never audited: CJK punctuation gets boxed, and Vim's z-commands are dead

Open PathGao opened this issue 4 months ago • 5 comments

#369 went through the editor options the app passes and fixed the ones that did not do what they claimed. It did not look at the options the app does not pass, where Monaco's defaults are in charge. Two reported problems come from there.

Fullwidth punctuation is boxed (#186, #94)

unicodeHighlight.ambiguousCharacters defaults to true. Fullwidth () and friends look like their ASCII counterparts, so Monaco outlines them. monaco.editor.create never sets unicodeHighlight — no occurrence anywhere in the repo.

This also explains the reporter's "clicking the buttons does nothing": the hover offers Adjust settings, which in standalone Monaco has no settings file to write to.

Every CJK user hits this while typing normal prose.

zz and the rest of the z-family do nothing (#104)

Upstream monaco-vim 0.4.4: actions.scrollToCursor computes a pixel y and calls cm.moveCurrentLineTo(y), while the adapter's moveCurrentLineTo(viewPosition) switches on "top" / "center" / "bottom" with no default branch. A number never matches, so it silently does nothing — zz, zt, zb, z., z- and z<CR> are all dead.

The ask

Rather than fixing these two one at a time, would you like a pass over Monaco's defaults for anything else that contradicts what the app presents? I'd bring a list before changing anything.

PathGao avatar Aug 02 '26 21:08 PathGao

@PathGao if we can fix the punctuation highlights we can queue it for this release, can get to the other Monaco defaults at a later date

alecdotdev avatar Aug 04 '26 23:08 alecdotdev

Status: the audit happened, and the first two findings have landed in #492.

~154 of Monaco's defaults were examined — 173 registered options, minus the 20 the app already sets, minus 8 the editor computes, plus 9 unset IGlobalEditorOptions. Six survived as worth changing. Two are now fixed:

  • selectionHighlight — the app ships a "Highlight Occurrences" setting that defaults to off, but that setting only drove occurrencesHighlight. Reading contrib/multicursor/browser/multicursor.js: SelectionHighlighter._isEnabled gates on selectionHighlight (id 122), while occurrencesHighlight (id 90) is consulted only at the end of _update to pick a decoration style. So the setting was turning off the style, not the highlight. Both are now driven from the one setting.
  • unusualLineTerminators — defaulted to 'prompt'. In VS Code that is a localized notification; in standalone Monaco StandaloneDialogService.doConfirm is literally mainWindow.confirm, so a document containing U+2028 raised a hardcoded-English browser dialog offering to rewrite the user's file, in an app shipping 26 locales. The guard exists to protect JavaScript string parsing, which is not a concern here. Now 'off', and nothing is lost visually — viewLineRenderer.js substitutes U+FFFD for LS/PS outside the renderControlCharacters branches.

One finding did not survive contact, and it is the interesting one. bracketPairColorization.enabled defaults to on, and the mechanism claim checks out — running Monaco's own code, LanguageBracketsConfiguration('markdown', conf) does colorize (), and prose parens tokenize as Other with the balanced-brackets bit set while ](url) is String and gets skipped. What is wrong is the fix: nothing in the bundle reads EditorOption.bracketPairColorization (id 21). The model's options come from the configuration service, and the only bridge from create-options to it is gated on isEditorConfigurationKey, which returns false for the bare key because the schema registers only the two dotted leaf keys. So passing it to monaco.editor.create is silently dropped. The real surface is model.updateOptions({ bracketColorizationOptions }) per model — a different change and a taste call, so it is documented in #492's Scope section rather than guessed at.

Left, and why:

  • autoDetectHighContrast — turning it off leaves the editor on stock vs/vs-dark rather than the app's themes, so it is not a one-line change.
  • wordSegmenterLocales — CJK word-wise navigation treats a clause as one word. Medium confidence and it needs a decision before code.
  • ariaLabel — 'Editor content', untranslated in a 26-locale app. Lowest priority.

Also worth recording rather than re-proposing: unicodeHighlight.invisibleCharacters diverges from VS Code deliberately. VS Code turns it off for Markdown (verified in extensions/markdown-basics/package.json, which also confirms #462 matched VS Code exactly); #462 kept it on, because an NBSP after a - breaks list parsing and nobody types one on purpose. That divergence is a choice, not an oversight.

Keeping this open for the three that remain.

PathGao avatar Aug 06 '26 04:08 PathGao

Both symptoms this issue names are fixed — unicodeHighlight.ambiguousCharacters in #462, the Vim z-family in #479 — and #186, #94 and #104 closed with them. What is left is the offer at the bottom: a pass over the defaults nobody chose. Here it is, measured against monaco-editor as bundled, not recalled.

For context, the options the editor does set today are wordBasedSuggestions: "off", quickSuggestions: false, unicodeHighlight.ambiguousCharacters: false, unusualLineTerminators: "off", plus the ones wired to settings. Everything below is a default nobody has looked at.

1. The same bug, one field over

unicodeHighlight has three flags. #462 turned off one of them.

ambiguousCharacters  false   ← #462
invisibleCharacters  true    ← still Monaco's default
nonBasicASCII        inUntrustedWorkspace

InvisibleCharacters holds 465 code points, and the ones a CJK writer types are in it. Measured by calling Monaco's own predicate:

U+3000 ideographic space   → outlined      ← the space bar in a Chinese/Japanese IME
U+00A0 no-break space      → outlined
U+2003 em space            → outlined
U+3164 hangul filler       → outlined

So the boxes came off the fullwidth punctuation and stayed on the fullwidth space. Same reporter, same typing, same hover with an Adjust settings button that leads nowhere in standalone Monaco.

Suggested: invisibleCharacters: false, or an allowedCharacters allowlist if the zero-width ones are worth keeping visible. This one I would do without further discussion — it is the unfinished half of a fix that already shipped.

2. emptySelectionClipboard: true — Ctrl+C with nothing selected copies the whole line

Monaco's default, and VS Code's behaviour. package.json says "The Notepad equivalent for Markdown", and in Notepad that keystroke does nothing at all. Someone who selects nothing, presses Ctrl+C to be safe, then pastes elsewhere gets a line they did not know they had copied.

Not obviously wrong — it is what half the audience expects. Naming it as a decision rather than a default.

3. copyWithSyntaxHighlighting: true — copying carries the colours

Copying out of the editor puts styled HTML on the clipboard beside the plain text. Paste into Word, Outlook or a rich-text field and you get coloured monospace rather than the Markdown you copied. For an app whose entire output is plain text, the styled flavour has no audience.

Suggested: false.

4. autoClosingBrackets: 'languageDefined' — and Markdown defines four pairs

// monaco-editor/esm/vs/basic-languages/markdown/markdown.js
autoClosingPairs: [
  { open: "{", close: "}" },
  { open: "[", close: "]" },
  { open: "(", close: ")" },
  { open: "<", close: ">", notIn: ["string"] },
]

So typing ( in a sentence inserts (), and < inserts <>. In a code editor that is help; in prose it is the editor typing into your paragraph. surroundingPairs also wraps a selection in ` — which for a Markdown writer is genuinely useful.

Worth a decision per pair rather than a blanket answer. My inclination: keep surrounding, drop auto-closing.

5. links: true — and nothing in the app handles the click

Monaco decorates URLs in the editor and opens them itself. The preview side is careful about this — handleLinkClick routes through the external opener — and the editor side sets no opener at all, so whatever standalone Monaco does is what happens. Given #394 (an untrusted .md can phone home), the same document can carry a link that is clicked in the editor rather than the preview.

Unverified: I could not settle what the standalone opener does inside the Tauri webview by reading the bundle, and it needs one click in a build to find out. Flagging rather than claiming.

6. No effect, listed for completeness

codeLens: true and hover are on, and the app registers no code-lens, hover or inline-completion provider, so they draw nothing. Leave them.


Order I would take these in: 1 on its own (it finishes #462), then 3, then 2 and 4 as decisions, then 5 once someone clicks a link in a build.

PathGao avatar Aug 07 '26 11:08 PathGao

Closing this out. Both symptoms in the title were fixed some time ago; what kept it open was the offer at the bottom — a pass over the defaults nobody chose — and that pass is now finished. Every item has an answer.

The two this issue is named after

Fullwidth punctuation is boxed (#186, #94) #462
zz and the z-family do nothing (#104) #479

All three of those issues closed with them.

The audit

# finding outcome
— selectionHighlight driven by the wrong setting #492
— unusualLineTerminators raising a hardcoded-English browser dialog #492
— bracketPairColorization withdrawn — nothing in the bundle reads EditorOption.bracketPairColorization; passing it to monaco.editor.create is silently dropped. The real surface is model.updateOptions, which is a different change
1 U+3000 still outlined — the space bar under every CJK IME #546
+ wordSegmenterLocales — word-wise navigation crosses a whole Chinese clause #546 (missed by the original audit)
3 copyWithSyntaxHighlighting — copying carries the colours in the branch for #207, where the clipboard paths were being collapsed anyway
2 emptySelectionClipboard not pursued
4 autoClosingBrackets not pursued
5 links: true with no opener measured — not a defect, see below
— autoDetectHighContrast, ariaLabel not pursued

Item 5, since it was the one with teeth

The concern was concrete: Monaco decorates URLs in the editor and hands the click to openerService, whose standalone default is

// openerService.js:109
if (matchesSomeScheme(href, Schemas.http, Schemas.https)) windowOpenNoOpener(href);
else mainWindow.location.href = href;

and in Tauri "the current window" is the application. Monaco's link detector recognises exactly three schemes — its state machine is commented "for http:// or https:// or file://" — so file: reaches that second branch, and an untrusted .md could carry one.

Tested in a build, both panes, both schemes:

editor preview
https:// opens externally opens externally
file:// nothing happens not linkified at all

The navigation is refused by the app's own CSP (default-src 'self' in tauri.conf.json). So the branch is reachable and inert, and item 5 comes down to a file: link in the editor that looks clickable and is not — a wart, not a hazard.

Worth writing down that what stops it is the CSP, not anything on this path. Loosening default-src for an unrelated reason would open it again silently, with nothing in the editor's link handling to notice. Relevant to #394.

Two things about the method, for whoever audits something next

The audit searched MenuId.EditorContext to decide what Monaco contributes to the editor's context menu, and concluded almost nothing usable. That was wrong: standalone actions register through contextMenuOpts instead, and Command Palette and Change All Occurrences are both there and both work without a language provider. It surfaced only because they went missing when that menu was redrawn — a search for one spelling of a thing is not a survey of the thing.

And bracketPairColorization is worth remembering as the shape of a plausible-but-wrong finding: the mechanism claim was right, the fix was unreachable, and nothing would have failed — not the type check, not a test, not the app — if it had been shipped.

PathGao avatar Aug 08 '26 09:08 PathGao

Item 3 landed in #548, which was the last one open. Closing.

Final state of the audit:

outcome
Fullwidth punctuation boxed (#186, #94) #462
zz and the z-family dead (#104) #479
selectionHighlight driven by the wrong setting #492
unusualLineTerminators raising an English browser dialog #492
U+3000 still boxed — the space bar under every CJK IME #546
wordSegmenterLocales — a Chinese clause counted as one word #546
copyWithSyntaxHighlighting — the macOS menu bar's Edit > Copy carried the colours #548
bracketPairColorization withdrawn — unreachable through create
links: true with no opener measured, inert behind the app's CSP
emptySelectionClipboard, autoClosingBrackets not pursued
autoDetectHighContrast, ariaLabel not pursued

One correction to that row, because the scope was written wider than it is. ⌘C and the editor's context menu were never affected: both go through Rust and have only ever written plain text. The one route that reached Monaco's own copy is Edit > Copy in the macOS menu bar, which is a PredefinedMenuItem::copy (#527) — it asks the webview to perform its copy, so #[cfg(target_os = "macos")] is also the whole of where this was ever visible.

Measured rather than argued, since the previous sentence was itself a guess the first time it was written. Same selection, same document, reading the pasteboard after each:

⌘C              «class utf8» 16   — nothing else
menu bar Copy   «class utf8» 18   — nothing else

Before #548 the second one carried a «class HTML» flavour beside the text. (For contrast, copying out of the preview pane produces utf8 10 + HTML 856 + RTF 422 + WebArchive 19,107,758 — that pane is a web page and is untouched by any of this. It is now #549.)

Three notes for whoever audits something next, since the method is the part that generalises:

A search for one spelling is not a survey. The audit used MenuId.EditorContext to decide what Monaco contributes to the editor's context menu and concluded almost nothing usable. Standalone actions register through contextMenuOpts instead, and Command Palette and Change All Occurrences are both there and both work without a language provider. It surfaced only because they went missing when that menu was redrawn in #548.

A correct mechanism can have an unreachable fix. bracketPairColorization was right about how Monaco colours brackets and wrong that passing the option to monaco.editor.create does anything: nothing in the bundle reads that key, and it is silently dropped. Nothing would have failed — not the type check, not a test, not the app — if it had shipped.

Reading the source is not measuring the behaviour. Item 5 traced a real path to mainWindow.location.href = href on a file: link, in an app where the current window is the application. In a build, nothing happens: the app's CSP refuses the navigation. What stops it is not anything on that path, which is worth remembering if default-src is ever loosened for an unrelated reason.

The same lesson, more expensively, in #548: the wry clipboard permission was traced through three crates, all correct, and did not fix the bug. samples/link-test.md is in the repo now so item 5 can be re-measured in one click.

PathGao avatar Aug 08 '26 10:08 PathGao