Skip to content

Commit

Permalink
'pastetoggle': Revert support for multi-key value (#6724)
Browse files Browse the repository at this point in the history
Reverts commit 337b617

Closes #6716 at the expense of not being able to use a
multi-key 'pastetoggle' manually.

Multi-key 'pastetoggle' can still be used when inserting the entire
option into the typebuffer at once (though the use here is
questionable).

Also remove those tests to do with waiting for the completion of
'pastetoggle' and mention in the documentation that 'pastetoggle'
doesn't wait for timeout.
  • Loading branch information
hardenedapple authored and justinmk committed May 31, 2017
1 parent 43f40b8 commit 033b1cb
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 18 deletions.
3 changes: 2 additions & 1 deletion runtime/doc/options.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4368,7 +4368,8 @@ A jump table for the options with a short description can be found at |Q_op|.
Note that typing <F10> in paste mode inserts "<F10>", since in paste
mode everything is inserted literally, except the 'pastetoggle' key
sequence.
When the value has several bytes 'ttimeoutlen' applies.
No timeout is used, this means that a multi-key 'pastetoggle' can not
be triggered manually.

*'pex'* *'patchexpr'*
'patchexpr' 'pex' string (default "")
Expand Down
2 changes: 1 addition & 1 deletion src/nvim/getchar.c
Original file line number Diff line number Diff line change
Expand Up @@ -1908,7 +1908,7 @@ static int vgetorpeek(int advance)
}

if ((mp == NULL || max_mlen >= mp_match_len)
&& keylen != KEYLEN_PART_MAP && keylen != KEYLEN_PART_KEY) {
&& keylen != KEYLEN_PART_MAP) {
// No matching mapping found or found a non-matching mapping that
// matches at least what the matching mapping matched
keylen = 0;
Expand Down
35 changes: 19 additions & 16 deletions test/functional/options/pastetoggle_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,35 @@ local command = helpers.command
local eq = helpers.eq
local eval = helpers.eval
local sleep = helpers.sleep
local expect = helpers.expect

describe("'pastetoggle' option", function()
before_each(function()
clear()
command('set nopaste')
command('set pastetoggle=a')
end)

it("toggles 'paste'", function()
eq(eval('&paste'), 0)
command('set pastetoggle=a')
eq(0, eval('&paste'))
feed('a')
-- Need another key so that the vgetorpeek() function returns.
feed('j')
eq(eval('&paste'), 1)
eq(1, eval('&paste'))
end)
it("multiple key 'pastetoggle' is waited for", function()
eq(eval('&paste'), 0)
local pastetoggle = 'lllll'
command('set pastetoggle=' .. pastetoggle)
command('set timeoutlen=1 ttimeoutlen=10000')
feed(pastetoggle:sub(0, 2))
-- sleep() for long enough that vgetorpeek() is gotten into, but short
-- enough that ttimeoutlen is not reached.
sleep(200)
feed(pastetoggle:sub(3, -1))
-- Need another key so that the vgetorpeek() function returns.
feed('j')
eq(eval('&paste'), 1)


it('does not wait for timeout', function()
command('set pastetoggle=abc')
command('set ttimeoutlen=9999999')
eq(0, eval('&paste'))
-- n.b. need <esc> to return from vgetorpeek()
feed('abc<esc>')
eq(1, eval('&paste'))
feed('ab')
sleep(10)
feed('c<esc>')
expect('bc')
eq(1, eval('&paste'))
end)
end)

0 comments on commit 033b1cb

Please sign in to comment.