]> git.gir.st - VimFx.git/commit
Improve copying of element text
authorSimon Lydell <simon.lydell@gmail.com>
Sun, 8 May 2016 06:31:56 +0000 (08:31 +0200)
committerSimon Lydell <simon.lydell@gmail.com>
Sun, 8 May 2016 06:31:56 +0000 (08:31 +0200)
commit8887be9e914be166d3b7f7740a406d31257c5be0
tree0524af63d8360dd24ab4686657ca2b424d9712ed
parent31a36cea04d7386edde3a119632e47c7e531b13f
Improve copying of element text

Slack uses markdown-style backtick syntax for code spans. Example:

    one `code` two

This is the rendered HTML for the above:

    <span class="message_body">
      one
      <code class="special_formatting">
        <span class="copyonly">`</span>code<span class="copyonly">`</span>
      </code>
      two
    </span>

Previously, `.textContent` was used to copy element text. Because those
backticks actually are there in the DOM, they get copied too. However,
that's unexpected because they're not visible. The `yv` command is
supposed to be equivalent to `zv<hintchars>y`, but this meant that it
wasn't.

This commit instead creates an actual selection and then invokes
Firefox's `cmd_copy` command (which is exactly what `zv` followed by `y`
does). A difference is that now you can see the created selection flash
for a split second, but I actually like that visual feedback.

This fix also has a positive effect on the `yf` command when copying
`contenteditable` elements. Take this markup:

    <div contenteditable="true">T</div>

Then type `<backspace>one<enter><enter>two` in it. Finally, copy the
element using `yf`.

Before, you'd get this:

```
onetwo
```

Now, you get the expected result:

```
one

two
```
extension/lib/commands-frame.coffee
extension/lib/commands.coffee
Imprint / Impressum