import { AutoCompleteLabel } from '../components/editor/auto_complete_decorator' ; import { SuggestionItem } from '../components/editor/suggestions' ; export default class EditorCompletionState { constructor ( public readonly query , public readonly label , public readonly pos_top , public readonly pos_left , public readonly suggestions , public readonly focus_idx ) { } searchSuggestions ( suggestions , query , top , left , label ) { if ( suggestions . length === 0 ) { return new EditorCompletionState ( query , null , top , left , suggestions , null ) ; } return new EditorCompletionState ( query , label , top , left , suggestions , this . focus_idx ) ; } cloneWithFocusIdx ( new_id ) { return new EditorCompletionState ( this . query , this . label , this . pos_top , this . pos_left , this . suggestions , new_id ) ; } downFocus ( ) { if ( this . label === null ) { return this ; } const i = this . focus_idx ; const next_idx = i === null || i >= this . suggestions . length - 1 ? 0 : i + 1 ; return this . cloneWithFocusIdx ( next_idx ) ; } upFocus ( ) { if ( this . label === null ) { return this ; } const i = this . focus_idx ; const next_idx = i === null || i <= 0 ? this . suggestions . length - 1 : i - 1 ; return this . cloneWithFocusIdx ( next_idx ) ; } } export const DefaultEditorCompletionState = new EditorCompletionState ( null , null , 0 , 0 , [ ] , null ) ;