import { Selection , TextDocument , TextEditor , TextEditorEdit , TextEditorRevealType , Position } from 'vscode' ; import { nextBoundaryLeft as left , nextBoundaryRight as right } from './boundaries' ; export function cursorSubwordLeft ( editor ) { cursorSubword ( editor , left , move ) ; } export function cursorSubwordRight ( editor ) { cursorSubword ( editor , right , move ) ; } export function cursorSubwordLeftSelect ( editor ) { cursorSubword ( editor , left , select ) ; } export function cursorSubwordRightSelect ( editor ) { cursorSubword ( editor , right , select ) ; } export function deleteSubwordLeft ( editor ) { deleteSubword ( editor , left ) ; } export function deleteSubwordRight ( editor ) { deleteSubword ( editor , right ) ; } function cursorSubword ( editor , next , sel ) { editor . selections = editor . selections . map ( s => sel ( s , next ( editor . document , s . active ) ) ) ; reveal ( editor ) ; } function deleteSubword ( editor , next ) { editor . edit ( e => editor . selections . forEach ( s => e . delete ( s . isEmpty ? s . with ( next ( editor . document , s . active ) ) : s ) ) ) . then ( ( ) => reveal ( editor ) ) ; } function reveal ( editor ) { if ( editor . selections . length === 1 ) { editor . revealRange ( editor . selection , TextEditorRevealType . InCenterIfOutsideViewport ) ; } } function move ( selection , boundary ) { return new Selection ( boundary , boundary ) ; } function select ( selection , boundary ) { return new Selection ( selection . anchor , boundary ) ; } type BoundaryFunc = ( doc : TextDocument , pos : Position ) => Position ; type SelectionFunc = ( selection : Selection , boundary : Position ) => Selection ;