Skip to content

Fix syntax highlighting and editor performance in the scripting terminal - #81

Open
rubensworks wants to merge 12 commits into
terminal-ux/4-feedbackfrom
terminal-ux/5-highlighting-performance
Open

rubensworks wants to merge 12 commits into
terminal-ux/4-feedbackfrom
terminal-ux/5-highlighting-performance

Conversation

@rubensworks

Copy link
Copy Markdown
Member

Phase 5 of the scripting terminal UX improvements, stacked on #80 (then #79, #78, #77). One commit per item.

Improve syntax highlighting in the script editor

Problem: Highlighting matched keywords as substrings. In a dev client:

  • var in variable, let in outlet and inside the string "let it be", and return in returnValue and inside a block comment were all highlighted as keywords.
  • The . in 1.5 was highlighted as a symbol.
  • Strings and comments weren't highlighted at all, even though a COMMENT style existed.
  • Highlighting ran per wrapped display line, so nothing could span lines.

Change:

  • The editor tokenizes the full script once: word boundaries, strings with escapes, template literals, numbers, line comments and block comments, plus a fuller keyword list. true, false, null and undefined use the existing CONSTANT style.
  • ILanguageHandler gets a default markupScript(String) built on markupLine, so other handlers keep working.
  • The editor slices the full-text markup per visual line.
  • 11 unit tests, and before/after screenshots checked.

Only re-wrap and re-highlight the editor text when it changes

Problem: The whole script was wrapped and highlighted again on every key press, including cursor movement, scrolling and selection changes.

Change: The text layout is cached until the text changes, and styled text is only built for visible lines.

Measured in the dev client with lines of about 95 characters (each wraps to about 3 rows):

Script Arrow key before Arrow key after Typing a character after
100 lines 2.4 ms 0.5 ms
500 lines 9.0 ms 0.4 ms
2000 lines 41 ms 0.3 ms 25 ms

The arrow key "before" column includes the tokenizer from the first commit. On master, a full rebuild was 6.8 / 15.9 / 40 ms.

Dropped from the original plan

A monospace font: 4-space indentation is clearly readable in the normal font, so it would change the look without fixing a demonstrated problem.

Testing

  • ./gradlew build passes, including the new unit tests.
  • ./gradlew runGameTestServer: all 22 tests pass.

Generated by Claude Code

Keywords were highlighted by substring, so they also matched inside
other words (var in variable, return in returnValue), strings and
comments, while strings, numbers and comments were not highlighted at
all. Highlighting was also done per wrapped line, so it couldn't handle
constructs spanning multiple lines.

Tokenize the full script instead, with word boundaries, strings,
numbers, and line and block comments, and add a markupScript method to
language handlers for this.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018MRyTdV3fSV5Q5NPGep4q9
The full script was wrapped and highlighted again on every key press,
including cursor movement, scrolling and selection changes, which took
9 ms for a 500-line script and 41 ms for a 2000-line script. Cache the
text layout until the text changes, and only build the styled text of
visible lines.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018MRyTdV3fSV5Q5NPGep4q9
@github-actions

github-actions Bot commented Oct 17, 2026 •

Copy link
Copy Markdown

Coverage Report for CI Build 39109367309

Coverage increased (+0.6%) to 43.978%

Details

  • Coverage increased (+0.6%) from the base build.
  • Patch coverage: No coverable lines changed in this PR.
  • 439 coverage regressions across 4 files.

Uncovered Changes

No uncovered changes found.

Coverage Regressions

439 previously-covered lines in 4 files lost coverage.

File Lines Losing Coverage Coverage
org/cyclops/integratedscripting/client/gui/component/input/WidgetTextArea.java 283 0.0%
org/cyclops/integratedscripting/client/gui/container/ContainerScreenTerminalScripting.java 142 0.0%
org/cyclops/integratedscripting/api/language/ILanguageHandler.java 7 0.0%
org/cyclops/integratedscripting/core/language/LanguageHandlerJavaScript.java 7 87.12%

Coverage Stats

Coverage Status
Relevant Lines: 3388
Covered Lines: 1621
Line Coverage: 47.85%
Relevant Branches: 1419
Covered Branches: 493
Branch Coverage: 34.74%
Branches in Coverage %: Yes
Coverage Strength: 23.26 hits per line

💛 - Coveralls

…-performance

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018MRyTdV3fSV5Q5NPGep4q9
…-performance

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018MRyTdV3fSV5Q5NPGep4q9
…-performance

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018MRyTdV3fSV5Q5NPGep4q9
…-performance

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018MRyTdV3fSV5Q5NPGep4q9
…-performance

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018MRyTdV3fSV5Q5NPGep4q9
…-performance

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018MRyTdV3fSV5Q5NPGep4q9
…-performance

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018MRyTdV3fSV5Q5NPGep4q9
…-performance

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018MRyTdV3fSV5Q5NPGep4q9
…-performance

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018MRyTdV3fSV5Q5NPGep4q9
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants