-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Writing Flow: Improve emulated caret positioning #5808
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -271,6 +271,12 @@ export function placeCaretAtVerticalEdge( container, isReverse, rect, mayUseScro | |
return; | ||
} | ||
|
||
// Offset by a buffer half the height of the caret rect. This is needed | ||
// because caretRangeFromPoint may default to the end of the selection if | ||
// offset is too close to the edge. It's unclear how to precisely calculate | ||
// this threshold; it may be the padded area of some combination of line | ||
// height, caret height, and font size. The buffer offset is effectively | ||
// equivalent to a point at half the height of a line of text. | ||
const buffer = rect.height / 2; | ||
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. Thanks, I should have better commented this. |
||
const editableRect = container.getBoundingClientRect(); | ||
const x = rect.left + ( rect.width / 2 ); | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Some remains form previous work?
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.
I added it intentionally, only because it's meant as a section marker, not a JSDoc for the variables being assigned. Definitely not related to the pull request, but I thought I could sneak it past. Apparently not without being noticed 😄
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.
Oh!
Isn't it common to do this then?
https://make.wordpress.org/core/handbook/best-practices/inline-documentation-standards/javascript/#multi-line-comments
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.
Which we could also use for the "dependencies" comments.
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.
Technically, yes (though in the specific example, "Module constants" is prone to laziness and ought to at least be accompanied by variable-specific JSDoc).
I was going to make a big argument about how I disagree with the double-vs-single asterisk, but I honestly don't care too much†. There is quite a bit of existing code which would need to be refactored.
Where I might disagree and champion for discussion is some implication from the standards that multi-line comments where each line is prefixed with
//
are not valid for inline code. Aside from being far more verbose, I find it hard to disambiguate between a comment and a JSDoc, where only the latter associates a relationship to the immediate following line (not lines, as in a comment describing a sequence of logic), tying back to good code commenting habits of commenting the "what" (JSDoc) from the "why"/"how" (logic flow comments).† ...Aside from my own personal-workflow incompatibility for me in that Docblock completion via DocBlockr extension only automates creation of intermediate-line asterisks for the double asterisk.
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.
Makes sense. I don't care that much either. :)
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.
Was just wondering.