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

trim leading/trailing <br> from pasted content #34

Open
jywarren opened this issue Jul 29, 2016 · 2 comments
Open

trim leading/trailing <br> from pasted content #34

jywarren opened this issue Jul 29, 2016 · 2 comments

Comments

@jywarren
Copy link
Collaborator

Following up from bevacqua/domador#7 (comment) -- related to inserted <br> when pasting content copied from a webpage (even a single word) in at least Chrome.

@jywarren
Copy link
Collaborator Author

jywarren commented Aug 4, 2016

Looking here: http://stackoverflow.com/questions/6035071/intercept-paste-event-in-javascript

And attempting to insert resulting intercepted text at the current insertion point here: https://github.com/bevacqua/woofmark/blob/master/src/InputHistory.js#L183

@jywarren
Copy link
Collaborator Author

jywarren commented Aug 4, 2016

Worked on this a bit but got stuck; I modified handlePaste() in InputHistory.js like this:

function handlePaste (state, e) {
  if (state.inputState && state.inputState.text !== state.surface.read(state.inputMode) && state.refreshing === null) {
    var pastedText;
    if (window.clipboardData && window.clipboardData.getData) { // IE
      pastedText = window.clipboardData.getData('Text');
    } else if (e.clipboardData && e.clipboardData.getData) {
      pastedText = e.clipboardData.getData('text/plain');
    }
    var chunks = state.inputState.getChunks();
    pastedText = pastedText.replace(/(\A<br\s?\/?\w?>)|(<br\s?\/?\w?>\z)/g, '');
    chunks.before += pastedText;
    state.inputState.setChunks(chunks);
    state.historyMode = 'paste';
    state.saveState();
    state.refreshState();
  }
  return false;
}

I successfully intercept the paste, but modifying chunks is not working; perhaps modifying state.inputState.getChunks() is not right.

I'll circle back to this later.

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

1 participant