@@ -225,6 +225,101 @@ export function updatePopupPositions() {
225225 } ) ;
226226}
227227
228+ export function updateSuggestionListPosition ( ) {
229+ const suggestionLists = document . querySelectorAll (
230+ ".collab-thread-body--input--textarea--suggestionsList"
231+ ) ;
232+
233+ if ( ! suggestionLists . length ) return ;
234+
235+ suggestionLists . forEach ( ( list ) => {
236+ if ( ! ( list instanceof HTMLElement ) ) return ;
237+
238+ const textarea = document . querySelector (
239+ ".collab-thread-body--input--textarea"
240+ ) as HTMLTextAreaElement | null ;
241+
242+ if ( ! textarea ) return ;
243+ const positionData = list . getAttribute ( "data-position" ) ;
244+ const parsedData = positionData ? JSON . parse ( positionData ) : null ;
245+ const showAbove = window . getComputedStyle ( list ) . bottom !== "auto" ;
246+ const textareaRect = textarea . getBoundingClientRect ( ) ;
247+ if ( showAbove ) {
248+ const lineHeight =
249+ parseInt ( window . getComputedStyle ( textarea ) . lineHeight ) || 20 ;
250+ const paddingTop =
251+ parseInt ( window . getComputedStyle ( textarea ) . paddingTop ) || 8 ;
252+ const cursorLineY =
253+ parsedData ?. cursorLineY || paddingTop + lineHeight ;
254+
255+ list . style . position = "fixed" ;
256+ list . style . bottom = `${ window . innerHeight - textareaRect . top - cursorLineY + lineHeight } px` ;
257+ list . style . top = "auto" ;
258+ } else {
259+ const lineHeight =
260+ parseInt ( window . getComputedStyle ( textarea ) . lineHeight ) || 20 ;
261+ const paddingTop =
262+ parseInt ( window . getComputedStyle ( textarea ) . paddingTop ) || 8 ;
263+
264+ const cursorLineY =
265+ parsedData ?. cursorLineY || paddingTop + lineHeight ;
266+
267+ list . style . position = "fixed" ;
268+ list . style . top = `${ textareaRect . top + cursorLineY } px` ;
269+ list . style . bottom = "auto" ;
270+ }
271+
272+ if ( ! positionData && textareaRect ) {
273+ const lineHeight =
274+ parseInt ( window . getComputedStyle ( textarea ) . lineHeight ) || 20 ;
275+ const paddingTop =
276+ parseInt ( window . getComputedStyle ( textarea ) . paddingTop ) || 8 ;
277+
278+ const positionInfo = {
279+ showAbove : showAbove ,
280+ cursorLineY : paddingTop + lineHeight ,
281+ } ;
282+ list . setAttribute ( "data-position" , JSON . stringify ( positionInfo ) ) ;
283+ }
284+
285+ const listRect = list . getBoundingClientRect ( ) ;
286+
287+ if ( ! showAbove && listRect . bottom > window . innerHeight ) {
288+ const lineHeight =
289+ parseInt ( window . getComputedStyle ( textarea ) . lineHeight ) || 20 ;
290+ const paddingTop =
291+ parseInt ( window . getComputedStyle ( textarea ) . paddingTop ) || 8 ;
292+ const cursorLineY =
293+ parsedData ?. cursorLineY || paddingTop + lineHeight ;
294+
295+ list . style . bottom = `${ window . innerHeight - textareaRect . top - cursorLineY + lineHeight } px` ;
296+ list . style . top = "auto" ;
297+
298+ if ( positionData ) {
299+ const updatedData = JSON . parse ( positionData ) ;
300+ updatedData . showAbove = true ;
301+ list . setAttribute ( "data-position" , JSON . stringify ( updatedData ) ) ;
302+ }
303+ } else if ( showAbove && listRect . top < 0 ) {
304+ const lineHeight =
305+ parseInt ( window . getComputedStyle ( textarea ) . lineHeight ) || 20 ;
306+ const paddingTop =
307+ parseInt ( window . getComputedStyle ( textarea ) . paddingTop ) || 8 ;
308+ const cursorLineY =
309+ parsedData ?. cursorLineY || paddingTop + lineHeight ;
310+
311+ list . style . top = `${ textareaRect . top + cursorLineY } px` ;
312+ list . style . bottom = "auto" ;
313+
314+ if ( positionData ) {
315+ const updatedData = JSON . parse ( positionData ) ;
316+ updatedData . showAbove = false ;
317+ list . setAttribute ( "data-position" , JSON . stringify ( updatedData ) ) ;
318+ }
319+ }
320+ } ) ;
321+ }
322+
228323export function calculatePopupPosition (
229324 button : HTMLElement ,
230325 popup : HTMLElement
0 commit comments