From 9cfbd7e3a265e3e62585c045fff400a9afa2e8e7 Mon Sep 17 00:00:00 2001 From: wsdjeg Date: Mon, 2 May 2022 20:46:43 +0800 Subject: [PATCH] feat(vimchat): support mouse left click --- bundle/vim-chat/autoload/chat/gitter.vim | 7 +++-- bundle/vim-chat/autoload/chat/windows.vim | 37 +++++++++++++++++++++++ 2 files changed, 42 insertions(+), 2 deletions(-) diff --git a/bundle/vim-chat/autoload/chat/gitter.vim b/bundle/vim-chat/autoload/chat/gitter.vim index 5a2681bfb..bc37c2a35 100644 --- a/bundle/vim-chat/autoload/chat/gitter.vim +++ b/bundle/vim-chat/autoload/chat/gitter.vim @@ -6,12 +6,15 @@ " License: GPLv3 "============================================================================= +if exists('s:room_jobs') + finish +endif + + let s:JOB = SpaceVim#api#import('job') let s:JSON = SpaceVim#api#import('data#json') let s:LOG = SpaceVim#logger#derive('gitter') -let s:room = '' - let g:chat_gitter_token = get(g:, 'chat_gitter_token', '') let s:room_jobs = {} diff --git a/bundle/vim-chat/autoload/chat/windows.vim b/bundle/vim-chat/autoload/chat/windows.vim index 899fd2561..a946acaeb 100644 --- a/bundle/vim-chat/autoload/chat/windows.vim +++ b/bundle/vim-chat/autoload/chat/windows.vim @@ -8,6 +8,7 @@ scriptencoding utf-8 let s:VIM = SpaceVim#api#import('vim') +let s:CMP = SpaceVim#api#import('vim#compatible') function! chat#windows#is_opened() abort return s:msg_win_opened @@ -67,6 +68,10 @@ function! chat#windows#open() abort call s:update_msg_screen() call s:update_statusline() call s:echon() + let mouse_left_lnum = 0 + let mouse_left_col = 0 + let mouse_left_release_lnum = 0 + let mouse_left_relsese_col = 0 while get(s:, 'quit_chating_win', 0) == 0 let char = s:VIM.getchar() if char !=# "\" && char !=# "\" @@ -84,6 +89,15 @@ function! chat#windows#open() abort let s:c_r_mode = 0 elseif char == "\" call s:enter() + elseif char ==# "\" + let mouse_left_lnum = v:mouse_lnum + let mouse_left_col = v:mouse_col + elseif char ==# "\" + let mouse_left_release_lnum = v:mouse_lnum + let mouse_left_relsese_col = v:mouse_col + if mouse_left_lnum !=# mouse_left_release_lnum && mouse_left_col !=# mouse_left_relsese_col + let @+= s:high_pso(mouse_left_lnum, mouse_left_col, mouse_left_release_lnum, mouse_left_relsese_col) + endif elseif char ==# "\" " 向右移动光标 let s:c_begin = s:c_begin . s:c_char @@ -193,6 +207,29 @@ function! chat#windows#open() abort normal! : endfunction +function! s:high_pso(l, c, rl, rc) abort + let [l, c, rl, rc] = [a:l, a:c, a:rl, a:rc] + call clearmatches() + if l ==# rl && c == rc + return '' + endif + " start_col is based s:update_msg_screen + let start_col = 38 + if rl > l + call s:CMP.matchaddpos('Visual', [[l, c, strlen(getline(l)) - c]]) + " if there are more than two lines + if rl - l >= 2 + for line in range(l + 1, rl - 1) + call s:CMP.matchaddpos('Visual', [[line, start_col, strlen(getline(line)) - start_col]]) + endfor + endif + call s:CMP.matchaddpos('Visual', [[rl, start_col, rc - start_col]]) + else + endif + redraw +endfunction + + function! s:get_str_with_width(str,width) abort let str = a:str let result = ''