Skip to content

Commit 6bbe6cc

Browse files
authored
Fix text filter pasting behaviour (#4300)
When pasting into a text filter in the Lookout UI, we trim the pasted text to remove whitespace at the start or end. Currently, the pasted text replaces the entire contents of the text box. This fix prevents the existing contents of the text box from being overwritten - rahter, it respects the cursor any selected text.
1 parent d443ddb commit 6bbe6cc

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

internal/lookoutui/src/components/lookout/JobsTableFilter.tsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,17 @@ const TextFilter = ({
215215
onChange={(e) => setTextFieldValue(e.currentTarget.value)}
216216
onPaste={(e) => {
217217
e.preventDefault()
218-
setTextFieldValue(e.clipboardData.getData("text/plain").trim())
218+
219+
const trimmedPastedText = e.clipboardData.getData("text/plain").trim()
220+
if (!ref.current || ref.current.selectionStart == null || ref.current.selectionEnd === null) {
221+
setTextFieldValue(trimmedPastedText)
222+
return
223+
}
224+
225+
const textBefore = textFieldValue.substring(0, ref.current.selectionStart)
226+
const textAfter = textFieldValue.substring(ref.current.selectionEnd)
227+
228+
setTextFieldValue(textBefore + trimmedPastedText + textAfter)
219229
}}
220230
value={textFieldValue}
221231
inputRef={ref}

0 commit comments

Comments
 (0)