annotate runtime/autoload/RstFold.vim @ 17775:b423bd231f33 v8.1.1884

patch 8.1.1884: cannot use mouse scroll wheel in popup in Insert mode commit https://github.com/vim/vim/commit/f0bc15c769b60f472d411b3ef98d57db510113c1 Author: Bram Moolenaar <Bram@vim.org> Date: Sun Aug 18 19:23:45 2019 +0200 patch 8.1.1884: cannot use mouse scroll wheel in popup in Insert mode Problem: Cannot use mouse scroll wheel in popup in Insert mode. Mouse clicks in popup close the popup menu. Solution: Check if the mouse is in a popup window. Do not let mouse events close the popup menu. (closes #4544)
author Bram Moolenaar <Bram@vim.org>
date Sun, 18 Aug 2019 19:30:03 +0200
parents 9d3d7b0f4861
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
14421
2f7e67dd088c Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1 " Author: Antony Lee <anntzer.lee@gmail.com>
2f7e67dd088c Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2 " Description: Helper functions for reStructuredText syntax folding
15334
9d3d7b0f4861 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 14421
diff changeset
3 " Last Modified: 2018-12-29
14421
2f7e67dd088c Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4
2f7e67dd088c Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5 function s:CacheRstFold()
15334
9d3d7b0f4861 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 14421
diff changeset
6 if !g:rst_fold_enabled
9d3d7b0f4861 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 14421
diff changeset
7 return
9d3d7b0f4861 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 14421
diff changeset
8 endif
9d3d7b0f4861 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 14421
diff changeset
9
14421
2f7e67dd088c Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
10 let closure = {'header_types': {}, 'max_level': 0, 'levels': {}}
2f7e67dd088c Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
11 function closure.Process(match) dict
2f7e67dd088c Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
12 let curline = getcurpos()[1]
2f7e67dd088c Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
13 if has_key(self.levels, curline - 1)
2f7e67dd088c Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
14 " For over+under-lined headers, the regex will match both at the
2f7e67dd088c Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
15 " overline and at the title itself; in that case, skip the second match.
2f7e67dd088c Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
16 return
2f7e67dd088c Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
17 endif
2f7e67dd088c Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
18 let lines = split(a:match, '\n')
2f7e67dd088c Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
19 let key = repeat(lines[-1][0], len(lines))
2f7e67dd088c Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
20 if !has_key(self.header_types, key)
2f7e67dd088c Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
21 let self.max_level += 1
2f7e67dd088c Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
22 let self.header_types[key] = self.max_level
2f7e67dd088c Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
23 endif
2f7e67dd088c Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
24 let self.levels[curline] = self.header_types[key]
2f7e67dd088c Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
25 endfunction
2f7e67dd088c Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
26 let save_cursor = getcurpos()
15334
9d3d7b0f4861 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 14421
diff changeset
27 let save_mark = getpos("'[")
14421
2f7e67dd088c Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
28 silent keeppatterns %s/\v^%(%(([=`:.'"~^_*+#-])\1+\n)?.{1,2}\n([=`:.'"~^_*+#-])\2+)|%(%(([=`:.''"~^_*+#-])\3{2,}\n)?.{3,}\n([=`:.''"~^_*+#-])\4{2,})$/\=closure.Process(submatch(0))/gn
2f7e67dd088c Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
29 call setpos('.', save_cursor)
15334
9d3d7b0f4861 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 14421
diff changeset
30 call setpos("'[", save_mark)
14421
2f7e67dd088c Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
31 let b:RstFoldCache = closure.levels
2f7e67dd088c Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
32 endfunction
2f7e67dd088c Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
33
2f7e67dd088c Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
34 function RstFold#GetRstFold()
15334
9d3d7b0f4861 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 14421
diff changeset
35 if !g:rst_fold_enabled
9d3d7b0f4861 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 14421
diff changeset
36 return
9d3d7b0f4861 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 14421
diff changeset
37 endif
9d3d7b0f4861 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 14421
diff changeset
38
14421
2f7e67dd088c Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
39 if !has_key(b:, 'RstFoldCache')
2f7e67dd088c Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
40 call s:CacheRstFold()
2f7e67dd088c Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
41 endif
2f7e67dd088c Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
42 if has_key(b:RstFoldCache, v:lnum)
2f7e67dd088c Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
43 return '>' . b:RstFoldCache[v:lnum]
2f7e67dd088c Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
44 else
2f7e67dd088c Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
45 return '='
2f7e67dd088c Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
46 endif
2f7e67dd088c Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
47 endfunction
2f7e67dd088c Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
48
2f7e67dd088c Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
49 function RstFold#GetRstFoldText()
15334
9d3d7b0f4861 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 14421
diff changeset
50 if !g:rst_fold_enabled
9d3d7b0f4861 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 14421
diff changeset
51 return
9d3d7b0f4861 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 14421
diff changeset
52 endif
9d3d7b0f4861 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 14421
diff changeset
53
14421
2f7e67dd088c Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
54 if !has_key(b:, 'RstFoldCache')
2f7e67dd088c Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
55 call s:CacheRstFold()
2f7e67dd088c Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
56 endif
2f7e67dd088c Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
57 let indent = repeat(' ', b:RstFoldCache[v:foldstart] - 1)
2f7e67dd088c Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
58 let thisline = getline(v:foldstart)
2f7e67dd088c Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
59 " For over+under-lined headers, skip the overline.
2f7e67dd088c Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
60 let text = thisline =~ '^\([=`:.''"~^_*+#-]\)\1\+$' ? getline(v:foldstart + 1) : thisline
2f7e67dd088c Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
61 return indent . text
2f7e67dd088c Update runtime files.
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
62 endfunction