-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix the raw tag editor broken and strange cursor behaviour #9766
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,13 +28,7 @@ export function utilGetSetValue(selection, value, shouldUpdate) { | |
} | ||
|
||
function stickyCursor(func) { | ||
// only certain input element types allow manipulating the cursor | ||
// see https://html.spec.whatwg.org/multipage/input.html#concept-input-apply | ||
const supportedTypes = ['text', 'search', 'url', 'tel', 'password']; | ||
return function() { | ||
if (!supportedTypes.includes(this.type)) { | ||
return; | ||
} | ||
const cursor = { start: this.selectionStart, end: this.selectionEnd }; | ||
func.apply(this, arguments); | ||
this.setSelectionRange(cursor.start, cursor.end); | ||
|
@@ -49,5 +43,12 @@ export function utilGetSetValue(selection, value, shouldUpdate) { | |
shouldUpdate = (a, b) => a !== b; | ||
} | ||
|
||
// only certain input element types allow manipulating the cursor | ||
// see https://html.spec.whatwg.org/multipage/input.html#concept-input-apply | ||
const supportedTypes = ['text', 'search', 'url', 'tel', 'password']; | ||
if (!supportedTypes.includes(this.type)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This does not quite work as probably intended: So, in practice, this condition is always fulfilled, even for input element types which would support cursor manipulation. As it still fixes the textarea/raw tag editor bug, I think we can keep it for the moment (even though #9233 is now an issue again), but I'll see if I can fix this a little bit better. 😊 |
||
return selection.each(setValue(value, shouldUpdate)); | ||
} | ||
|
||
return selection.each(stickyCursor(setValue(value, shouldUpdate))); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Based on the code that changed, these regressions were probably introduced in 14c7525 (related to #8769 and 2b64d70). I believe the intention was for this line to memoize the cursor position before setting the value in order to restore that position afterwards. It needs to go to the very top of this function before the call to
apply()
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks, it seems like this bug was present even before this PR (#9764)
I've reworked the logic now so it also fixes #9764. are there any specific cases that are still broken for you?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I was a bit unclear. 14c7525 attempted to fix #9233 but barely avoided fixing #9764 while creating other regressions. As far as I can tell, these changes do fix both issues.