Skip to content

Commit

Permalink
Merge pull request #201 from aioutecism/feature/smart-relative-line-n…
Browse files Browse the repository at this point in the history
…umbers

Adding `smartRelativeLineNumbers` config
  • Loading branch information
aioutecism authored May 27, 2018
2 parents 53e42cd + 89eaab7 commit 8878a5b
Show file tree
Hide file tree
Showing 8 changed files with 78 additions and 0 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ Set to `false` to disable `Ctrl+<key>` keybindings.

Set to `true` to start in Insert mode when opening files.

#### `amVim.smartRelativeLineNumbers`

`Boolean`, Default: `false`

Set to `true` to will make line numbers relative when not in Insert mode.

#### `amVim.vimStyleNavigationInListView`

`Boolean`, Default: `true`
Expand Down
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@
"default": false,
"description": "Set to `true` to start in Insert mode when opening files."
},
"amVim.smartRelativeLineNumbers": {
"type": "boolean",
"default": false,
"description": "Set to `true` to will make line numbers relative when not in Insert mode."
},
"amVim.vimStyleNavigationInListView": {
"type": "boolean",
"default": true,
Expand Down
37 changes: 37 additions & 0 deletions src/Actions/RelativeLineNumbers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { TextEditorLineNumbersStyle, window } from 'vscode';

export class ActionRelativeLineNumbers {

static on(): Thenable<boolean> {
return new Promise((resolve) => {
setTimeout(() => {
const activeTextEditor = window.activeTextEditor;

if (! activeTextEditor) {
return Promise.resolve(false);
}

activeTextEditor.options.lineNumbers = TextEditorLineNumbersStyle.Relative;

resolve(true);
}, 0);
});
}

static off(): Thenable<boolean> {
return new Promise((resolve) => {
setTimeout(() => {
const activeTextEditor = window.activeTextEditor;

if (! activeTextEditor) {
return Promise.resolve(false);
}

activeTextEditor.options.lineNumbers = TextEditorLineNumbersStyle.On;

resolve(true);
}, 0);
});
}

}
6 changes: 6 additions & 0 deletions src/Configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ export class Configuration {
private static _defaultModeID: ModeID;
static get defaultModeID(): ModeID { return this._defaultModeID; }

private static _smartRelativeLineNumbers: boolean;
static get smartRelativeLineNumbers(): boolean { return this._smartRelativeLineNumbers; }

static init(): void {
if (this.isReady) {
return;
Expand All @@ -29,7 +32,10 @@ export class Configuration {
private static onDidChangeConfiguration(): void {
this.updateCache();
this.updateKeybindingContexts();

this._defaultModeID = this.getExtensionSetting<boolean>('startInInsertMode', false) ? ModeID.INSERT : ModeID.NORMAL;
this._smartRelativeLineNumbers = this.getExtensionSetting<boolean>('smartRelativeLineNumbers', false);

UtilWord.updateCharacterKindCache(this.getEditorSetting<string>('wordSeparators', '`~!@#$%^&*()-=+[{]}\\|;:\'",.<>/?'));
}

Expand Down
6 changes: 6 additions & 0 deletions src/Modes/Insert.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import {window, TextEditor, Position} from 'vscode';
import {Mode, ModeID} from './Mode';
import {Configuration} from '../Configuration';
import {MatchResultKind} from '../Mappers/Generic';
import {CommandMap} from '../Mappers/Command';
import {ActionRelativeLineNumbers} from '../Actions/RelativeLineNumbers';
import {ActionInsert} from '../Actions/Insert';
import {ActionDelete} from '../Actions/Delete';
import {ActionSelection} from '../Actions/Selection';
Expand Down Expand Up @@ -54,6 +56,10 @@ export class ModeInsert extends Mode {
this.textEditor = window.activeTextEditor;

this.startRecord();

if (Configuration.smartRelativeLineNumbers) {
ActionRelativeLineNumbers.off();
}
}

exit(): void {
Expand Down
6 changes: 6 additions & 0 deletions src/Modes/Normal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ import {TextEditorRevealType} from 'vscode';
import {StaticReflect} from '../LanguageExtensions/StaticReflect';
import {SymbolMetadata} from '../Symbols/Metadata';
import {Mode, ModeID} from './Mode';
import {Configuration} from '../Configuration';
import {CommandMap} from '../Mappers/Command';
import {ActionBlockCursor} from '../Actions/BlockCursor';
import {ActionRelativeLineNumbers} from '../Actions/RelativeLineNumbers';
import {ActionMoveCursor} from '../Actions/MoveCursor';
import {ActionPage} from '../Actions/Page';
import {ActionInsert} from '../Actions/Insert';
Expand Down Expand Up @@ -246,6 +248,10 @@ export class ModeNormal extends Mode {
super.enter();

ActionBlockCursor.on();

if (Configuration.smartRelativeLineNumbers) {
ActionRelativeLineNumbers.on();
}
}

exit(): void {
Expand Down
6 changes: 6 additions & 0 deletions src/Modes/Visual.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ import {StaticReflect} from '../LanguageExtensions/StaticReflect';
import {SymbolMetadata} from '../Symbols/Metadata';
import {RangeOffset} from '../Types/RangeOffset';
import {Mode, ModeID} from './Mode';
import {Configuration} from '../Configuration';
import {CommandMap} from '../Mappers/Command';
import {ActionRelativeLineNumbers} from '../Actions/RelativeLineNumbers';
import {ActionMoveCursor} from '../Actions/MoveCursor';
import {ActionPage, PageMoveType} from '../Actions/Page';
import {ActionSelection} from '../Actions/Selection';
Expand Down Expand Up @@ -143,6 +145,10 @@ export class ModeVisual extends Mode {
super.enter();

ActionSelection.expandToOne();

if (Configuration.smartRelativeLineNumbers) {
ActionRelativeLineNumbers.on();
}
}

private _recordedCommandMaps: CommandMap[];
Expand Down
6 changes: 6 additions & 0 deletions src/Modes/VisualLine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ import {StaticReflect} from '../LanguageExtensions/StaticReflect';
import {SymbolMetadata} from '../Symbols/Metadata';
import {RangeOffset} from '../Types/RangeOffset';
import {Mode, ModeID} from './Mode';
import {Configuration} from '../Configuration';
import {CommandMap} from '../Mappers/Command';
import {ActionRelativeLineNumbers} from '../Actions/RelativeLineNumbers';
import {ActionMoveCursor} from '../Actions/MoveCursor';
import {ActionPage, PageMoveType} from '../Actions/Page';
import {ActionSelection} from '../Actions/Selection';
Expand Down Expand Up @@ -148,6 +150,10 @@ export class ModeVisualLine extends Mode {
super.enter();

ActionSelection.expandToLine();

if (Configuration.smartRelativeLineNumbers) {
ActionRelativeLineNumbers.on();
}
}

private _recordedCommandMaps: CommandMap[];
Expand Down

0 comments on commit 8878a5b

Please sign in to comment.