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

Paste over selection #39

Closed
mike76-dev opened this issue Nov 30, 2020 · 5 comments
Closed

Paste over selection #39

mike76-dev opened this issue Nov 30, 2020 · 5 comments

Comments

@mike76-dev
Copy link
Contributor

When a part of text is selected, paste replaces it but the caret moves by textToPaste.length (desired) + selection.length (undesired). When no text is selected, the behavior is as expected.

@mike76-dev
Copy link
Contributor Author

mike76-dev commented Nov 30, 2020

    preventDefault(event)
    const text = ((event as any).originalEvent || event).clipboardData.getData("text/plain")
    const s = window.getSelection()
    const selection = !s.isCollapsed
    const pos = save()
    insert(text)
    highlight(editor)
    if (selection) {
        restore({start: pos.end, end: pos.end})
    } else {
        restore({start: pos.end + text.length, end: pos.end + text.length})
    }
  }

@antonmedv
Copy link
Owner

Can you make pr this change?

mike76-dev added a commit to mike76-dev/codejar that referenced this issue Nov 30, 2020
@mike76-dev
Copy link
Contributor Author

Done.

@antonmedv
Copy link
Owner

Your solution was wrong. Fixed it in 84aaec0

@mike76-dev
Copy link
Contributor Author

Was it? Well, to be honest, I just used some of your code in browser js where it did show this issue and my solution was able to fix it. Sorry if it didn't work out for you. Appreciate your work though.

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