MCPcopy Index your code
hub / github.com/SplootCode/splootcode / InsertBox

Class InsertBox

packages/editor/src/components/insert_box.tsx:150–589  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

148
149@observer
150export class InsertBox extends React.Component<InsertBoxProps, InsertBoxState> {
151 private inputRef: React.RefObject<HTMLInputElement>
152 private suggestionsRef: React.RefObject<HTMLUListElement>
153
154 constructor(props: InsertBoxProps) {
155 super(props)
156 this.inputRef = React.createRef()
157 this.suggestionsRef = React.createRef()
158
159 this.state = {
160 userInput: '',
161 autoWidth: this.getWidth(''),
162 cursorPosition: null,
163 filteredSuggestions: [],
164 autocompleters: [],
165 staticSuggestions: [],
166 staticSuggestionKeys: new Set(),
167 activeSuggestion: 0,
168 }
169 }
170
171 static getDerivedStateFromProps(props: InsertBoxProps, state: InsertBoxState) {
172 const { cursorPosition, selection } = props
173
174 if (cursorPosition !== state.cursorPosition) {
175 const cursors = selection.getAutocompleteNodeCursors()
176 const staticSuggestions: RenderedSuggestion[] = []
177 const autocompleters: CursorAutocompleter[] = []
178 const categorySet = new Set<NodeCategory>()
179
180 for (const cursor of cursors) {
181 const childSetBlock = cursor.listBlock
182 const category = childSetBlock.childSet.nodeCategory
183 if (!childSetBlock.allowInsert() || category in categorySet) {
184 continue
185 }
186
187 const autocompleter = new CursorAutocompleter(cursor, categorySet)
188 categorySet.add(category)
189 getAutocompleteRegistry()
190 .getAdapatableCategories(category)
191 .forEach((cat) => categorySet.add(cat))
192 autocompleters.push(autocompleter)
193 staticSuggestions.push(...autocompleter.getStaticSuggestions())
194 }
195
196 const staticSuggestionKeys: Set<string> = new Set()
197 staticSuggestions.forEach((suggestion) => {
198 staticSuggestionKeys.add(suggestion.key)
199 })
200
201 const userInput = selection.state === SelectionState.Cursor ? '' : state.userInput
202
203 return {
204 filteredSuggestions: [],
205 userInput: userInput,
206 cursorPosition: cursorPosition,
207 staticSuggestions: staticSuggestions,

Callers

nothing calls this directly

Calls 8

onSelectedMethod · 0.95
handleEarlyInsertMethod · 0.95
stringWidthFunction · 0.90
filterSuggestionsFunction · 0.85
backspaceMethod · 0.80
exitEditMethod · 0.80

Tested by

no test coverage detected