Skip to content
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

Is it better to add position support to Cursor.js #209

Open
haozhechen opened this issue Jun 6, 2018 · 1 comment
Open

Is it better to add position support to Cursor.js #209

haozhechen opened this issue Jun 6, 2018 · 1 comment

Comments

@haozhechen
Copy link

The Cursor support for medium.js is good but not enough. Like it lacks some basic cursor position support, i.e. if the cursor is at the end of the element?

I tried to add two functions: isCaretAtBegin and isCaretAtEnd. which could support some basic cursor position support.

Medium.Cursor.prototype = {
	......
	isCaretAtBegin: function (el) {
            var sel = rangy.getSelection();
            return sel.anchorOffset === 0;
        },
	isCaretAtEnd: function (el) {
            var sel = rangy.getSelection();
            return sel.anchorOffset === el.innerText.length;
        }
}

However, when using this two function upon nested elements, the

rangy.getSelection() 

will get the last inner element other than the very outer element.
For example, use

rangy.getSelection() 

for element

<p>this is a test paragraph,<span>ho ho ho</span></p>,

the selection will be the inner span other than the p element, so even you place the cursor at the end of this paragraph, the

el.innerText.length 

will be 33 and

sel.anchorOffset

will be 8.

I just wonder if these kind of functions is needed, I could work on it to improve Medium.js since this is the best open source WYSIWYG editor I have met.

@robertleeplummerjr
Copy link
Collaborator

We welcome it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants