diff --git a/packages/app-gnome/src/widgets/source-view.ts b/packages/app-gnome/src/widgets/source-view.ts index 5f75ab68..565adcc1 100644 --- a/packages/app-gnome/src/widgets/source-view.ts +++ b/packages/app-gnome/src/widgets/source-view.ts @@ -262,6 +262,7 @@ export class SourceView extends Adw.Bin implements SourceViewWidget { */ public set editable(value: boolean) { this._sourceView.set_editable(value); + this.updateCurrentLineHighlight(); } /** @@ -315,7 +316,7 @@ export class SourceView extends Adw.Bin implements SourceViewWidget { this.copyClipboardSignalId = undefined; } } - this._sourceView.highlight_current_line = true; + this.updateCurrentLineHighlight(); } /** @@ -800,6 +801,14 @@ export class SourceView extends Adw.Bin implements SourceViewWidget { this.events.dispatch("changed", { code: this.code }); } + /** + * Highlight the cursor line only while editing: in read-only code blocks + * the idle cursor (sitting at the last line) would look like a selection. + */ + private updateCurrentLineHighlight() { + this._sourceView.highlight_current_line = this._sourceView.editable; + } + /** * Update the style of the source view. * Used internally to update the style of the source view when the theme changes. @@ -812,7 +821,7 @@ export class SourceView extends Adw.Bin implements SourceViewWidget { scheme = this.schemeManager.get_scheme(isDark ? "Adwaita-dark" : "Adwaita"); } if (scheme) this.buffer.set_style_scheme(scheme); - this._sourceView.set_highlight_current_line(true); + this.updateCurrentLineHighlight(); } /** diff --git a/packages/learn/tsx/components/gtk/gtk-code.compontent.tsx b/packages/learn/tsx/components/gtk/gtk-code.compontent.tsx index d6c8ede4..c734c960 100644 --- a/packages/learn/tsx/components/gtk/gtk-code.compontent.tsx +++ b/packages/learn/tsx/components/gtk/gtk-code.compontent.tsx @@ -160,7 +160,9 @@ export class GtkCode extends GtkWidget { */ protected parseAttributes(props: GtkCodeProps): Partial { let language = props.language || ""; - let readonly = props.readonly || false; + // MDX code blocks are documentation, so they always render read-only; + // the only editable SourceView is the editor itself + let readonly = props.readonly ?? true; let copyable = props.copyable || false; let unselectable = props.unselectable || false; let noLineNumbers = props.noLineNumbers || false;