@@ -175,35 +175,29 @@ export const singleLineEditorScroll = (editor: Editor) => {
175175 return
176176 }
177177
178- setTimeout ( ( ) => {
179- const singleLineEditor = editor . view . dom . closest (
180- '.single-line-editor' ,
181- ) as HTMLElement
182- if ( singleLineEditor ) {
183- // Get the current cursor position
184- const pos = editor . state . selection . $head . pos
185- let targetVariable = findClosestVariableNode (
186- editor ,
187- pos ,
188- singleLineEditor ,
189- )
190-
191- // If we still haven't found it, fall back to the last variable
192- if ( ! targetVariable ) {
193- const variables = Array . from (
194- singleLineEditor . getElementsByClassName ( 'node-variable' ) ,
195- ) as HTMLElement [ ]
196- if ( variables . length > 0 ) {
197- targetVariable = variables [ variables . length - 1 ]
198- }
178+ const singleLineEditor = editor . view . dom . closest (
179+ '.single-line-editor' ,
180+ ) as HTMLElement
181+ if ( singleLineEditor ) {
182+ // Get the current cursor position
183+ const pos = editor . state . selection . $head . pos
184+ let targetVariable = findClosestVariableNode ( editor , pos , singleLineEditor )
185+
186+ // If we still haven't found it, fall back to the last variable
187+ if ( ! targetVariable ) {
188+ const variables = Array . from (
189+ singleLineEditor . getElementsByClassName ( 'node-variable' ) ,
190+ ) as HTMLElement [ ]
191+ if ( variables . length > 0 ) {
192+ targetVariable = variables [ variables . length - 1 ]
199193 }
194+ }
200195
201- // Scroll to the target variable if found
202- if ( targetVariable ) {
203- scrollVariableIntoView ( targetVariable , singleLineEditor )
204- }
196+ // Scroll to the target variable if found
197+ if ( targetVariable ) {
198+ scrollVariableIntoView ( targetVariable , singleLineEditor )
205199 }
206- } , 10 )
200+ }
207201}
208202
209203export function findClosestVariableNode (
0 commit comments