Skip to content

Commit

Permalink
Remove line highlighting and cursor from code area
Browse files Browse the repository at this point in the history
This commit hides the highlight on selected line (active line and gutter
line indicators) and the user cursor before user interacts with the code
area.

This gives cleaner look to initial UI and the behavior is similar to how
modern editors like VSCode acts when a code is shown for the first time.

When code is generated automatically, generated code is already
highlighted with a custom marker. The indication of a specific line is
not necessary by default and clutter the view.
  • Loading branch information
undergroundwires committed Oct 10, 2024
1 parent 2f31bc7 commit c2c9d91
Showing 1 changed file with 27 additions and 2 deletions.
29 changes: 27 additions & 2 deletions src/presentation/components/Code/TheCodeArea.vue
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,33 @@ function initializeEditor(
editor.setTheme(`ace/theme/${theme}`);
editor.setReadOnly(true);
editor.setAutoScrollEditorIntoView(true);
editor.setShowPrintMargin(false); // hides vertical line
editor.getSession().setUseWrapMode(true); // So code is readable on mobile
editor.setShowPrintMargin(false); // Hide the vertical line
editor.getSession().setUseWrapMode(true); // Make code readable on mobile
hideActiveLineAndCursorUntilInteraction(editor);
return editor;
}
function hideActiveLineAndCursorUntilInteraction(editor: ace.Ace.Editor) {
hideActiveLineAndCursor(editor);
editor.session.on('change', () => {
editor.session.selection.clearSelection();
hideActiveLineAndCursor(editor);
});
editor.session.selection.on('changeSelection', () => {
showActiveLineAndCursor(editor);
});
}
function hideActiveLineAndCursor(editor: ace.Ace.Editor) {
editor.setHighlightGutterLine(false); // Remove highlighting on line number column
editor.setHighlightActiveLine(false); // Remove highlighting throughout the line
editor.renderer.$cursorLayer.element.style.display = 'none'; // hide cursor

Check failure on line 182 in src/presentation/components/Code/TheCodeArea.vue

View workflow job for this annotation

GitHub Actions / build-web (macos, development)

Property '$cursorLayer' does not exist on type 'VirtualRenderer'.

Check failure on line 182 in src/presentation/components/Code/TheCodeArea.vue

View workflow job for this annotation

GitHub Actions / build-web (macos, production)

Property '$cursorLayer' does not exist on type 'VirtualRenderer'.

Check failure on line 182 in src/presentation/components/Code/TheCodeArea.vue

View workflow job for this annotation

GitHub Actions / build-web (macos, test)

Property '$cursorLayer' does not exist on type 'VirtualRenderer'.

Check failure on line 182 in src/presentation/components/Code/TheCodeArea.vue

View workflow job for this annotation

GitHub Actions / build-web (ubuntu, development)

Property '$cursorLayer' does not exist on type 'VirtualRenderer'.

Check failure on line 182 in src/presentation/components/Code/TheCodeArea.vue

View workflow job for this annotation

GitHub Actions / build-web (ubuntu, production)

Property '$cursorLayer' does not exist on type 'VirtualRenderer'.

Check failure on line 182 in src/presentation/components/Code/TheCodeArea.vue

View workflow job for this annotation

GitHub Actions / build-web (ubuntu, test)

Property '$cursorLayer' does not exist on type 'VirtualRenderer'.

Check failure on line 182 in src/presentation/components/Code/TheCodeArea.vue

View workflow job for this annotation

GitHub Actions / build-web (windows, development)

Property '$cursorLayer' does not exist on type 'VirtualRenderer'.

Check failure on line 182 in src/presentation/components/Code/TheCodeArea.vue

View workflow job for this annotation

GitHub Actions / build-web (windows, production)

Property '$cursorLayer' does not exist on type 'VirtualRenderer'.

Check failure on line 182 in src/presentation/components/Code/TheCodeArea.vue

View workflow job for this annotation

GitHub Actions / build-web (windows, test)

Property '$cursorLayer' does not exist on type 'VirtualRenderer'.
}
function showActiveLineAndCursor(editor: ace.Ace.Editor) {
editor.setHighlightGutterLine(true); // Show highlighting on line number column
editor.setHighlightActiveLine(true); // Show highlighting throughout the line
editor.renderer.$cursorLayer.element.style.display = ''; // Show cursor

Check failure on line 188 in src/presentation/components/Code/TheCodeArea.vue

View workflow job for this annotation

GitHub Actions / build-web (macos, development)

Property '$cursorLayer' does not exist on type 'VirtualRenderer'.

Check failure on line 188 in src/presentation/components/Code/TheCodeArea.vue

View workflow job for this annotation

GitHub Actions / build-web (macos, production)

Property '$cursorLayer' does not exist on type 'VirtualRenderer'.

Check failure on line 188 in src/presentation/components/Code/TheCodeArea.vue

View workflow job for this annotation

GitHub Actions / build-web (macos, test)

Property '$cursorLayer' does not exist on type 'VirtualRenderer'.

Check failure on line 188 in src/presentation/components/Code/TheCodeArea.vue

View workflow job for this annotation

GitHub Actions / build-web (ubuntu, development)

Property '$cursorLayer' does not exist on type 'VirtualRenderer'.

Check failure on line 188 in src/presentation/components/Code/TheCodeArea.vue

View workflow job for this annotation

GitHub Actions / build-web (ubuntu, production)

Property '$cursorLayer' does not exist on type 'VirtualRenderer'.

Check failure on line 188 in src/presentation/components/Code/TheCodeArea.vue

View workflow job for this annotation

GitHub Actions / build-web (ubuntu, test)

Property '$cursorLayer' does not exist on type 'VirtualRenderer'.

Check failure on line 188 in src/presentation/components/Code/TheCodeArea.vue

View workflow job for this annotation

GitHub Actions / build-web (windows, development)

Property '$cursorLayer' does not exist on type 'VirtualRenderer'.

Check failure on line 188 in src/presentation/components/Code/TheCodeArea.vue

View workflow job for this annotation

GitHub Actions / build-web (windows, production)

Property '$cursorLayer' does not exist on type 'VirtualRenderer'.

Check failure on line 188 in src/presentation/components/Code/TheCodeArea.vue

View workflow job for this annotation

GitHub Actions / build-web (windows, test)

Property '$cursorLayer' does not exist on type 'VirtualRenderer'.
return editor;
}
Expand Down

0 comments on commit c2c9d91

Please sign in to comment.