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

Pasting content in webmode inserts content in incorrect place #3960

Closed
ashervb opened this issue Nov 25, 2015 · 14 comments
Closed

Pasting content in webmode inserts content in incorrect place #3960

ashervb opened this issue Nov 25, 2015 · 14 comments
Labels
- Bug tracker - Bug :-( stale marked as a stale issue/pr (usually by a bot) Web

Comments

@ashervb
Copy link
Contributor

ashervb commented Nov 25, 2015

<div></div>
<div |id="foo"></div>

Cursor is at |, deleting id=foo and attempting to paste into the first div will result in

 id="foo"<div></div>
<div></div>

rather than the expected

<div id="foo"></div>
<div></div>
@CestDiego
Copy link
Contributor

I can confirm this.

@StreakyCobra
Copy link
Contributor

What are the steps you are using for delete and paste? I tried it here by using v to select the id="foo", then d to delete it, then p on the line above to paste it and it worked.

@ashervb
Copy link
Contributor Author

ashervb commented Nov 29, 2015

<div></div>
<div |id="foo"></div>

Cursor is at |, type dt>, move to the > in the <div> above and hit P results in the above error. Curiously enough if I move to the v in <div> and hit p I get the following result::

<div></div>
 id="foo
<div>

@TheBB
Copy link
Collaborator

TheBB commented Nov 29, 2015

I definitely can't confirm any of your behaviour. It works as expected here.

@ashervb
Copy link
Contributor Author

ashervb commented Nov 29, 2015

I did some additional testing, the error only occurs for me when I have the html (as a sanity check I have that as my only enabled layer currently and a default .spacemacs file) layer enabled in my dotspacemacs-configuration-layers

@StreakyCobra
Copy link
Contributor

Same as @TheBB, I can't reproduce, with html layer enabled too. Can you paste here the result of SPC h d s ?

@ashervb
Copy link
Contributor Author

ashervb commented Nov 30, 2015

System Info

  • OS: gnu/linux
  • Emacs: 24.5.1
  • Spacemacs: 0.104.6
  • Spacemacs branch: master (rev. 50ec30b)
  • Distribution: spacemacs
  • Layers:
(html)

I should also note that it seems the behavior doesn't occur with a fresh buffer (e.g. just paste the above in). In order to trigger, it seems that you need to work within the buffer for a bit. The most reliable way I've found is to paste in the above, then swap the lines twice by typing gg ddp k ddp before attempting the above steps.

@StreakyCobra
Copy link
Contributor

Ok I was able to reproduce it, by playing indeed a few time with the buffer. Looks like an upstream bug for me, probably between web-mode and evil

@tbo
Copy link

tbo commented Sep 22, 2016

I am not a spacemacs user, but I am experiencing the same issue. I was able to confirm @StreakyCobra's web-mode<->evil theory. I already filed a bug in the web-mode bugtracker (fxbois/web-mode#756), but the maintainer couldn't help me out and pointed me to stackoverflow, where I posted the problem as well (http://emacs.stackexchange.com/questions/24542/pasting-text-doesnt-work-properly-in-evil-web-mode). After one month without any comments, I reposted it in the evil bugtracker (https://bitbucket.org/lyro/evil/issues/703/pasting-text-doesnt-work-properly-in). To this day, i haven't got any answers.

Any ideas, what I could try next?

@TheBB
Copy link
Collaborator

TheBB commented Sep 22, 2016

Well, there's always reading the source code and figuring it out yourself, if all else fails.

@honmaple
Copy link

honmaple commented Sep 5, 2017

Confirm this.I can reproduce this bug,the code:

     <li style="padding:0 20px;border-left:1px solid #666;border-right:1px solid #666;">
        <a href="">
        <span class="item-count"><b>100</b></span>
        <span class="item-name">category</span>
        </a>
    </li>

when I use evil-visual-state to copy padding:0 20px;,and then use p to paste text,it's would be normal.

    <li style="padding:0 20px;padding:0 20px;border-left:1px solid #666;border-right:1px solid #666;">
        <a href="">
        <span class="item-count"><b>100</b></span>
        <span class="item-name">category</span>
        </a>
    </li>

but when I use yy to copy first line,the code:

    <li style="padding:0 20px;border-left:1px solid #666;border-right:1px solid #666;">
    <li style="padding:0 20px;border-left:1px solid #666;border-right:1px solid #666;">
        <a href="">
        <span class="item-count"><b>100</b></span>
        <span class="item-name">category</span>
        </a>
    </li>

then use evil-visual-state to copy padding:0 20px; and use p to paste text,the bug was reproduced.

    <li style="padding:0 20px;border-left:1px solid #666;border-right:1px solid #666;">
    <li style="padding:0 20px;border-left:1px solid #666;border-right:1px solid #666;">
padding:0 20px
        <a href="">
        <span class="item-count"><b>100</b></span>
        <span class="item-name">category</span>
        </a>
    </li>

I read the evil code and test it,and I found the bug was caused by evil-define-command evil-paste-after

          (if (functionp yank-handler)
              (let ((evil-paste-count count)
                    ;; for non-interactive use
                    (this-command #'evil-paste-after))
                (insert-for-yank text))

(functionp yank-handler) should be nil If I use evil-visual-state to copy text,but it's t after I use yy to copy some text.

Unfortunately,I don't konw how to fix it?:joy:

@bschwehn
Copy link

bschwehn commented Sep 13, 2017

As a workaround I changed evil-common function evil-yank-characters to

(defun evil-yank-characters (beg end &optional register yank-handler)
  "Saves the characters defined by the region BEG and END in the kill-ring."
  (let ((text (filter-buffer-substring beg end)))
; added the following two lines
		(unless yank-handler
			(setq text (propertize text 'yank-handler nil)))
    (when yank-handler
      (setq text (propertize text 'yank-handler (list yank-handler))))

This seems to work so far, but not sure about any possible side-effects.
Also could not figure out why this happens with web mode only.

@bschwehn
Copy link

bschwehn commented Sep 13, 2017

Edit: wrong information, cannot delete comment.

@github-actions
Copy link

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Please let us know if this issue is still valid!

@github-actions github-actions bot added the stale marked as a stale issue/pr (usually by a bot) label Feb 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
- Bug tracker - Bug :-( stale marked as a stale issue/pr (usually by a bot) Web
Projects
None yet
Development

No branches or pull requests

7 participants