Skip to content
Open
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
34 changes: 20 additions & 14 deletions src/state/editors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,10 @@ export class PerEditorState implements vscode.Disposable {
public dispose() {
this._clearDecorations(this._mode);

const options = this._editor.options,
mode = this._mode,
const mode = this._mode,
vscodeMode = mode.modes.vscodeMode;

options.cursorStyle = vscodeMode.cursorStyle;
options.lineNumbers = vscodeMode.lineNumbers;
this._updateEditorOptions(vscodeMode);

if (this._isVisible) {
this._isVisible = false;
Expand Down Expand Up @@ -175,11 +173,8 @@ export class PerEditorState implements vscode.Disposable {
for (const prop of props) {
switch (prop) {
case "cursorStyle":
this._editor.options.cursorStyle = mode.cursorStyle;
break;

case "lineNumbers":
this._editor.options.lineNumbers = mode.lineNumbers;
this._updateEditorOptions(mode);
break;

case "decorations":
Expand Down Expand Up @@ -232,12 +227,10 @@ export class PerEditorState implements vscode.Disposable {
* @deprecated Do not call -- internal implementation detail.
*/
public notifyDidBecomeActive() {
const { editor, mode } = this;
const { mode } = this;

this.extension.statusBar.activeModeSegment.setContent(mode.name);

editor.options.lineNumbers = mode.lineNumbers;
editor.options.cursorStyle = mode.cursorStyle;
this._updateEditorOptions(mode);

return vscode.commands.executeCommand("setContext", extensionName + ".mode", mode.name);
}
Expand Down Expand Up @@ -382,12 +375,25 @@ export class PerEditorState implements vscode.Disposable {
editor.setDecorations(this.extension.editors.characterDecorationType, []);
}

editor.options.cursorStyle = mode.cursorStyle;
editor.options.lineNumbers = mode.lineNumbers;

this._updateOffscreenSelectionsIndicators(mode);
}

private _updateEditorOptions(mode: Mode) {
const editor = this._editor;

// By default, zen mode hides line numbers. Unfortunately, there is no way
// for us to detect whether zen mode is currently active, so we guess
// instead.
const isMaybeInZenMode = this.extension.hideLineNumbersInZenMode
&& editor.options.lineNumbers === vscode.TextEditorLineNumbersStyle.Off;

if (!isMaybeInZenMode) {
editor.options.lineNumbers = mode.lineNumbers;
}
editor.options.cursorStyle = mode.cursorStyle;
}

private _updateSelectionsAfterBehaviorChange(mode: Mode) {
const editor = this._editor,
document = editor.document,
Expand Down
15 changes: 15 additions & 0 deletions src/state/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ export class Extension implements vscode.Disposable {
return this._gotoMenus as ReadonlyMap<string, Menu>;
}

private _hideLineNumbersInZenMode = false;

public get hideLineNumbersInZenMode() {
return this._hideLineNumbersInZenMode;
}

// State.
// ==========================================================================

Expand Down Expand Up @@ -168,6 +174,15 @@ export class Extension implements vscode.Disposable {
true,
);

// Configuration: VS Code.
this.observePreference<boolean>(
"zenMode.hideLineNumbers",
(value) => {
this._hideLineNumbersInZenMode = value;
},
/*triggerNow=*/ true,
);

this._subscriptions.push(
// Update configuration automatically.
vscode.workspace.onDidChangeConfiguration((e) => {
Expand Down