55
66import * as vscode from 'vscode' ;
77import { getDeepestNode , findNextWord , findPrevWord , getNode } from './util' ;
8- import Node from '@emmetio/node ' ;
8+ import { Node , CssNode , Rule , Property } from 'EmmetNode ' ;
99
1010export function nextItemStylesheet ( startOffset : vscode . Position , endOffset : vscode . Position , editor : vscode . TextEditor , rootNode : Node ) : vscode . Selection {
11- let currentNode = getNode ( rootNode , endOffset , true ) ;
11+ let currentNode = < CssNode > getNode ( rootNode , endOffset , true ) ;
1212 if ( ! currentNode ) {
13- currentNode = rootNode ;
13+ currentNode = < CssNode > rootNode ;
1414 }
1515
1616 // Full property is selected, so select full property value next
@@ -19,16 +19,16 @@ export function nextItemStylesheet(startOffset: vscode.Position, endOffset: vsco
1919 }
2020
2121 // Part or whole of propertyValue is selected, so select the next word in the propertyValue
22- if ( currentNode . type === 'property' && startOffset . isAfterOrEqual ( currentNode . valueToken . start ) && endOffset . isBeforeOrEqual ( currentNode . valueToken . end ) ) {
22+ if ( currentNode . type === 'property' && startOffset . isAfterOrEqual ( ( < Property > currentNode ) . valueToken . start ) && endOffset . isBeforeOrEqual ( ( < Property > currentNode ) . valueToken . end ) ) {
2323 let singlePropertyValue = getSelectionFromProperty ( currentNode , editor . document , startOffset , endOffset , false , 'next' ) ;
2424 if ( singlePropertyValue ) {
2525 return singlePropertyValue ;
2626 }
2727 }
2828
2929 // Cursor is in the selector or in a property
30- if ( ( currentNode . type === 'rule' && endOffset . isBefore ( currentNode . selectorToken . end ) )
31- || ( currentNode . type === 'property' && endOffset . isBefore ( currentNode . valueToken . end ) ) ) {
30+ if ( ( currentNode . type === 'rule' && endOffset . isBefore ( ( < Rule > currentNode ) . selectorToken . end ) )
31+ || ( currentNode . type === 'property' && endOffset . isBefore ( ( < Property > currentNode ) . valueToken . end ) ) ) {
3232 return getSelectionFromNode ( currentNode , editor . document ) ;
3333 }
3434
@@ -48,19 +48,19 @@ export function nextItemStylesheet(startOffset: vscode.Position, endOffset: vsco
4848
4949}
5050
51- export function prevItemStylesheet ( startOffset : vscode . Position , endOffset : vscode . Position , editor : vscode . TextEditor , rootNode : Node ) : vscode . Selection {
52- let currentNode = getNode ( rootNode , startOffset ) ;
51+ export function prevItemStylesheet ( startOffset : vscode . Position , endOffset : vscode . Position , editor : vscode . TextEditor , rootNode : CssNode ) : vscode . Selection {
52+ let currentNode = < CssNode > getNode ( rootNode , startOffset ) ;
5353 if ( ! currentNode ) {
5454 currentNode = rootNode ;
5555 }
5656
5757 // Full property value is selected, so select the whole property next
58- if ( currentNode . type === 'property' && startOffset . isEqual ( currentNode . valueToken . start ) && endOffset . isEqual ( currentNode . valueToken . end ) ) {
58+ if ( currentNode . type === 'property' && startOffset . isEqual ( ( < Property > currentNode ) . valueToken . start ) && endOffset . isEqual ( ( < Property > currentNode ) . valueToken . end ) ) {
5959 return getSelectionFromNode ( currentNode , editor . document ) ;
6060 }
6161
6262 // Part of propertyValue is selected, so select the prev word in the propertyValue
63- if ( currentNode . type === 'property' && startOffset . isAfterOrEqual ( currentNode . valueToken . start ) && endOffset . isBeforeOrEqual ( currentNode . valueToken . end ) ) {
63+ if ( currentNode . type === 'property' && startOffset . isAfterOrEqual ( ( < Property > currentNode ) . valueToken . start ) && endOffset . isBeforeOrEqual ( ( < Property > currentNode ) . valueToken . end ) ) {
6464 let singlePropertyValue = getSelectionFromProperty ( currentNode , editor . document , startOffset , endOffset , false , 'prev' ) ;
6565 if ( singlePropertyValue ) {
6666 return singlePropertyValue ;
@@ -76,7 +76,7 @@ export function prevItemStylesheet(startOffset: vscode.Position, endOffset: vsco
7676 while ( prevNode . nextSibling && startOffset . isAfterOrEqual ( prevNode . nextSibling . end ) ) {
7777 prevNode = prevNode . nextSibling ;
7878 }
79- prevNode = getDeepestNode ( prevNode ) ;
79+ prevNode = < CssNode > getDeepestNode ( prevNode ) ;
8080
8181 return getSelectionFromProperty ( prevNode , editor . document , startOffset , endOffset , false , 'prev' ) ;
8282
@@ -88,7 +88,7 @@ function getSelectionFromNode(node: Node, document: vscode.TextDocument): vscode
8888 return ;
8989 }
9090
91- let nodeToSelect = node . type === 'rule' ? node . selectorToken : node ;
91+ let nodeToSelect = node . type === 'rule' ? ( < Rule > node ) . selectorToken : node ;
9292 return new vscode . Selection ( nodeToSelect . start , nodeToSelect . end ) ;
9393}
9494
@@ -97,27 +97,28 @@ function getSelectionFromProperty(node: Node, document: vscode.TextDocument, sel
9797 if ( ! node || node . type !== 'property' ) {
9898 return ;
9999 }
100+ const propertyNode = < Property > node ;
100101
101- let propertyValue = node . valueToken . stream . substring ( node . valueToken . start , node . valueToken . end ) ;
102- selectFullValue = selectFullValue || ( direction === 'prev' && selectionStart . isEqual ( node . valueToken . start ) && selectionEnd . isBefore ( node . valueToken . end ) ) ;
102+ let propertyValue = propertyNode . valueToken . stream . substring ( propertyNode . valueToken . start , propertyNode . valueToken . end ) ;
103+ selectFullValue = selectFullValue || ( direction === 'prev' && selectionStart . isEqual ( propertyNode . valueToken . start ) && selectionEnd . isBefore ( propertyNode . valueToken . end ) ) ;
103104
104105 if ( selectFullValue ) {
105- return new vscode . Selection ( node . valueToken . start , node . valueToken . end ) ;
106+ return new vscode . Selection ( propertyNode . valueToken . start , propertyNode . valueToken . end ) ;
106107 }
107108
108109 let pos ;
109110 if ( direction === 'prev' ) {
110- if ( selectionStart . isEqual ( node . valueToken . start ) ) {
111+ if ( selectionStart . isEqual ( propertyNode . valueToken . start ) ) {
111112 return ;
112113 }
113- pos = selectionStart . isAfter ( node . valueToken . end ) ? propertyValue . length : selectionStart . character - node . valueToken . start . character ;
114+ pos = selectionStart . isAfter ( propertyNode . valueToken . end ) ? propertyValue . length : selectionStart . character - propertyNode . valueToken . start . character ;
114115 }
115116
116117 if ( direction === 'next' ) {
117- if ( selectionEnd . isEqual ( node . valueToken . end ) && ( selectionStart . isAfter ( node . valueToken . start ) || propertyValue . indexOf ( ' ' ) === - 1 ) ) {
118+ if ( selectionEnd . isEqual ( propertyNode . valueToken . end ) && ( selectionStart . isAfter ( propertyNode . valueToken . start ) || propertyValue . indexOf ( ' ' ) === - 1 ) ) {
118119 return ;
119120 }
120- pos = selectionEnd . isEqual ( node . valueToken . end ) ? - 1 : selectionEnd . character - node . valueToken . start . character - 1 ;
121+ pos = selectionEnd . isEqual ( propertyNode . valueToken . end ) ? - 1 : selectionEnd . character - propertyNode . valueToken . start . character - 1 ;
121122 }
122123
123124
@@ -126,8 +127,8 @@ function getSelectionFromProperty(node: Node, document: vscode.TextDocument, sel
126127 return ;
127128 }
128129
129- const newSelectionStart = ( < vscode . Position > node . valueToken . start ) . translate ( 0 , newSelectionStartOffset ) ;
130- const newSelectionEnd = ( < vscode . Position > node . valueToken . start ) . translate ( 0 , newSelectionEndOffset ) ;
130+ const newSelectionStart = ( < vscode . Position > propertyNode . valueToken . start ) . translate ( 0 , newSelectionStartOffset ) ;
131+ const newSelectionEnd = ( < vscode . Position > propertyNode . valueToken . start ) . translate ( 0 , newSelectionEndOffset ) ;
131132
132133 return new vscode . Selection ( newSelectionStart , newSelectionEnd ) ;
133134}
0 commit comments