Skip to content

Commit

Permalink
Merge pull request #62 from kamecha/feature/message-cursor
Browse files Browse the repository at this point in the history
チャンネルタイムラインを表示してるところで、カーソルとかの見た目をよくした
  • Loading branch information
kamecha authored Nov 28, 2023
2 parents 7f8d1da + b7c321b commit bc17aa6
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 7 deletions.
1 change: 1 addition & 0 deletions autoload/helper.vim
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ function! helper#define_highlight() abort
highlight! VtraQUserName ctermfg=lightgray guifg=lightgray cterm=bold
highlight! VtraQScreenName ctermfg=lightmagenta guifg=lightmagenta cterm=bold
highlight! link VtraQQuote Comment
highlight! link VtraQMessage Keyword
endfunction
56 changes: 52 additions & 4 deletions autoload/traqvim.vim
Original file line number Diff line number Diff line change
Expand Up @@ -17,29 +17,37 @@ endfunction

function! traqvim#draw_timeline(bufNum) abort
call setbufvar(a:bufNum, "&modifiable", 1)
let index = 0
let start = 1
let winnr = bufwinid(a:bufNum)
let width = winwidth(winnr)
for message in getbufvar(a:bufNum, "channelTimeline")
let body = traqvim#make_message_body(message, width)
let end = start + len(body)
let end = start + len(body) - 1
let message.position = #{ index: index, start: start, end: end }
call setbufline(a:bufNum, start, body)
let start = end
let start = end + 1
let index = index + 1
endfor
call setbufvar(a:bufNum, "&modifiable", 0)
endfunction

function! traqvim#draw_forward_messages(bufNum, messages) abort
call setbufvar(a:bufNum, "&modifiable", 1)
" この関数を呼ばれる前に追加分が既にバッファ変数に登録されてる
let timeline = getbufvar(a:bufNum, "channelTimeline")
let index = len(timeline) - len(a:messages)
" startをバッファの最下値にする
let start = len(getbufline(a:bufNum, 1, '$')) + 1
let winnr = bufwinid(a:bufNum)
let width = winwidth(winnr)
for message in a:messages
let body = traqvim#make_message_body(message, width)
let end = start + len(body)
let end = start + len(body) - 1
let message.position = #{ index: index, start: start, end: end }
call setbufline(a:bufNum, start, body)
let start = end
let start = end + 1
let index = index + 1
endfor
call setbufvar(a:bufNum, "&modifiable", 0)
endfunction
Expand Down Expand Up @@ -83,3 +91,43 @@ function! traqvim#make_message_body(message, width) abort
let messageBody = header + rows + quote + footer
return messageBody
endfunction

function! traqvim#get_message_buf(curline, bufNum) abort
let timeline = getbufvar(a:bufNum, "channelTimeline")
let message = copy(timeline)->filter({ _, v -> v.position["start"] <= a:curline && a:curline <= v.position["end"] })
if len(message) == 0
return {}
endif
return message[0]
endfunction

function! traqvim#get_message() abort
let curline = line(".")
return traqvim#get_message_buf(curline, bufnr("%"))
endfunction

function! traqvim#message_prev() abort
let cur = traqvim#get_message()
if empty(cur)
return
endif
let prev_index = cur.position["index"] - 1
if prev_index < 0
return
endif
let prev = b:channelTimeline[prev_index]
call cursor([prev.position["start"], 0])
endfunction

function! traqvim#message_next() abort
let cur = traqvim#get_message()
if empty(cur)
return
endif
let next_index = cur.position["index"] + 1
if next_index >= len(b:channelTimeline)
return
endif
let next = b:channelTimeline[next_index]
call cursor([next.position["start"], 0])
endfunction
5 changes: 5 additions & 0 deletions denops/traqvim/type.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ export interface UnreadChannel extends traq.UnreadChannel {

export interface Message extends traq.Message {
user: traq.User;
position?: {
index: number;
start: number;
end: number;
};
quote?: Message[];
}

Expand Down
10 changes: 10 additions & 0 deletions doc/traqvim.jax
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ License : MIT license {{{
インターフェイス |traqvim-interface|
変数 |traqvim-variables|
コマンド |traqvim-commands|
キーマッピング |traqvim-keymappings|
関数 |traqvim-functions|
TODO |traqvim-todo|
更新履歴 |traqvim-changelog|
Expand Down Expand Up @@ -91,6 +92,15 @@ g:traqvim#token_file_path
:TraqMessageSend *:TraqMessageSend*
メッセージバッファにおいて有効であり、メッセージを対象チャンネルに送信します

------------------------------------------------------------------------------
キーマッピング *traqvim-keymappings*

<Plug>(traqvim-next) *<Plug>(traqvim-next)*
次のメッセージへカーソルを移動させます

<Plug>(traqvim-prev) *<Plug>(traqvim-prev)*
前のメッセージへカーソルを移動させます

------------------------------------------------------------------------------
レイアウト *traqvim-channel-layout*

Expand Down
12 changes: 9 additions & 3 deletions ftplugin/traqvim.vim
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,19 @@ nnoremap <buffer><silent> r
\ :TraqReload<CR>
nnoremap <buffer><silent> o
\ :TraqMessageOpen<CR>
nnoremap <buffer><silent> <Plug>(traqvim-next)
\ <Cmd>call traqvim#message_next()<CR>
nnoremap <buffer><silent> <Plug>(traqvim-prev)
\ <Cmd>call traqvim#message_prev()<CR>
" filetypeがtraqvimの時かつ、ウィンドウのサイズが変更された時だけ実行

augroup traqvim
autocmd!
autocmd WinResized *
\ if &ft == 'traqvim' |
\ call traqvim#redraw_recursive(winlayout()) |
\ endif
\ if &ft == 'traqvim' |
\ call traqvim#redraw_recursive(winlayout()) |
\ endif
autocmd CursorMoved *
\ :match VtraQMessage '\v^─*%(─%#|%#─)─*\n%(%(.*[^─].*|)\n)+─+$|^─+\n%(%(.*[^─].*|)\n)+─*%(─%#|%#─)─*$|^─+\n%(%(.*[^─].*|)\n)*%(.*[^─].*%#.*|.*%#.*[^─].*|%#)\n%(%(.*[^─].*|)\n)*─+$'
augroup END

0 comments on commit bc17aa6

Please sign in to comment.