Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions packages/app-gnome/src/widgets/source-view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ export class SourceView extends Adw.Bin implements SourceViewWidget {
*/
public set editable(value: boolean) {
this._sourceView.set_editable(value);
this.updateCurrentLineHighlight();
}

/**
Expand Down Expand Up @@ -315,7 +316,7 @@ export class SourceView extends Adw.Bin implements SourceViewWidget {
this.copyClipboardSignalId = undefined;
}
}
this._sourceView.highlight_current_line = true;
this.updateCurrentLineHighlight();
}

/**
Expand Down Expand Up @@ -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.
Expand All @@ -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();
}

/**
Expand Down
4 changes: 3 additions & 1 deletion packages/learn/tsx/components/gtk/gtk-code.compontent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,9 @@ export class GtkCode extends GtkWidget<GtkCodeProps> {
*/
protected parseAttributes(props: GtkCodeProps): Partial<GtkCodeProps> {
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;
Expand Down
Loading