File tree Expand file tree Collapse file tree 3 files changed +11
-15
lines changed
Expand file tree Collapse file tree 3 files changed +11
-15
lines changed Original file line number Diff line number Diff line change 1- import { Position , Selection , TextDocument , TextEditor } from 'vscode' ;
1+ import { Position , Selection , TextDocument } from 'vscode' ;
22
33export class Cursor {
44 public readonly start : Position ;
@@ -20,8 +20,8 @@ export class Cursor {
2020 return new Cursor ( sel . anchor , sel . active ) ;
2121 }
2222
23- public isValid ( textEditor : TextEditor ) {
24- return this . start . isValid ( textEditor ) && this . stop . isValid ( textEditor ) ;
23+ public isValid ( document : TextDocument ) {
24+ return this . start . isValid ( document ) && this . stop . isValid ( document ) ;
2525 }
2626
2727 public equals ( other : Cursor ) : boolean {
Original file line number Diff line number Diff line change @@ -247,7 +247,7 @@ declare module 'vscode' {
247247 */
248248 obeyStartOfLine ( document : vscode . TextDocument ) : Position ;
249249
250- isValid ( textEditor : vscode . TextEditor ) : boolean ;
250+ isValid ( document : vscode . TextDocument ) : boolean ;
251251 }
252252}
253253
@@ -559,17 +559,13 @@ Position.prototype.obeyStartOfLine = function (
559559 : this ;
560560} ;
561561
562- Position . prototype . isValid = function ( this : Position , textEditor : vscode . TextEditor ) : boolean {
562+ Position . prototype . isValid = function ( this : Position , document : vscode . TextDocument ) : boolean {
563563 try {
564- // line
565- // TODO: this `|| 1` seems dubious...
566- const lineCount = TextEditor . getLineCount ( textEditor ) || 1 ;
567- if ( this . line >= lineCount ) {
564+ if ( this . line >= document . lineCount ) {
568565 return false ;
569566 }
570567
571- // char
572- const charCount = TextEditor . getLineLength ( this . line ) ;
568+ const charCount = document . lineAt ( this . line ) . range . end . character ;
573569 if ( this . character > charCount + 1 ) {
574570 return false ;
575571 }
Original file line number Diff line number Diff line change @@ -131,7 +131,7 @@ export class VimState implements vscode.Disposable {
131131 return this . cursor . start ;
132132 }
133133 public set cursorStartPosition ( value : Position ) {
134- if ( ! value . isValid ( this . editor ) ) {
134+ if ( ! value . isValid ( this . document ) ) {
135135 Logger . warn ( `invalid cursor start position. ${ value . toString ( ) } .` ) ;
136136 }
137137 this . cursor = this . cursor . withNewStart ( value ) ;
@@ -144,7 +144,7 @@ export class VimState implements vscode.Disposable {
144144 return this . cursor . stop ;
145145 }
146146 public set cursorStopPosition ( value : Position ) {
147- if ( ! value . isValid ( this . editor ) ) {
147+ if ( ! value . isValid ( this . document ) ) {
148148 Logger . warn ( `invalid cursor stop position. ${ value . toString ( ) } .` ) ;
149149 }
150150 this . cursor = this . cursor . withNewStop ( value ) ;
@@ -178,8 +178,8 @@ export class VimState implements vscode.Disposable {
178178
179179 const map = new Map < string , Cursor > ( ) ;
180180 for ( const cursor of value ) {
181- if ( ! cursor . isValid ( this . editor ) ) {
182- Logger . warn ( `invalid cursor position. ${ cursor . toString ( ) } . ` ) ;
181+ if ( ! cursor . isValid ( this . document ) ) {
182+ Logger . warn ( `Invalid cursor position: ${ cursor . toString ( ) } ` ) ;
183183 }
184184
185185 // use a map to ensure no two cursors are at the same location.
You can’t perform that action at this time.
0 commit comments