-
Notifications
You must be signed in to change notification settings - Fork 151
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
[SPIKE] Add delete to start of line for MacOS #636
base: master
Are you sure you want to change the base?
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 |
---|---|---|
|
@@ -62,6 +62,40 @@ function findOffsetInSection(section, node, offset) { | |
} | ||
} | ||
|
||
// TODO: expose as utility function, update cursor._findNodeForPosition | ||
function findNodeForPosition(position) { | ||
let { section } = position; | ||
let node, offset; | ||
if (section.isCardSection) { | ||
offset = 0; | ||
if (position.offset === 0) { | ||
node = section.renderNode.element.firstChild; | ||
} else { | ||
node = section.renderNode.element.lastChild; | ||
} | ||
} else if (section.isBlank) { | ||
node = section.renderNode.cursorElement; | ||
offset = 0; | ||
} else { | ||
let { marker, offsetInMarker } = position; | ||
if (marker.isAtom) { | ||
if (offsetInMarker > 0) { | ||
// FIXME -- if there is a next marker, focus on it? | ||
offset = 0; | ||
node = marker.renderNode.tailTextNode; | ||
} else { | ||
offset = 0; | ||
node = marker.renderNode.headTextNode; | ||
} | ||
} else { | ||
node = marker.renderNode.element; | ||
offset = offsetInMarker; | ||
} | ||
} | ||
|
||
return { node, offset }; | ||
} | ||
|
||
let Position, BlankPosition; | ||
|
||
Position = class Position { | ||
|
@@ -101,6 +135,24 @@ Position = class Position { | |
return Position.fromNode(_renderTree, node, offset); | ||
} | ||
|
||
static atStartOfLine(position, editor) { | ||
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. It seems like this method should be able to become an instance method or getter.
|
||
let isPostBoundary = position.isHeadOfPost(); | ||
if (isPostBoundary) { | ||
return position; | ||
} | ||
|
||
let { node, offset } = findNodeForPosition(position); | ||
|
||
let range = document.createRange(); | ||
range.setStart(node, offset); | ||
range.setEnd(node, offset); | ||
|
||
let { y, height } = range.getBoundingClientRect(); | ||
let { left } = position.section.renderNode.element.getBoundingClientRect(); | ||
|
||
return Position.atPoint(left, y + height / 2, editor); | ||
} | ||
|
||
static blankPosition() { | ||
return new BlankPosition(); | ||
} | ||
|
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.
This seems to have been copied from
cursor.js
, the code should probably be de-duplicated?