-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
use modifier instead of some "Vnew"/"New" commands
- Loading branch information
Showing
11 changed files
with
69 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
function! docbase#buffer_action#teams_list#open(lnum, opener = "edit") | ||
call denops#notify("docbase", "bufferAction", [bufnr(), "open", {"lnum": a:lnum, "opener": a:opener}]) | ||
function! docbase#buffer_action#teams_list#open(lnum, mods="") | ||
call denops#notify("docbase", "bufferAction", [bufnr(), "open", {"lnum": a:lnum, "mods": a:mods}]) | ||
endfunction |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,17 @@ | ||
function! docbase#open#teams_list(opener="edit") | ||
call denops#notify("docbase", "openBuffer", ["TeamList", a:opener]) | ||
function! docbase#open#teams_list(mods="") | ||
call denops#notify("docbase", "openBuffer", ["TeamList", a:mods]) | ||
endfunction | ||
|
||
function! docbase#open#posts_list(domain, opener="edit") | ||
call denops#notify("docbase", "openBuffer", ["PostList", {"domain": a:domain}, a:opener]) | ||
function! docbase#open#posts_list(domain, mods="") | ||
call denops#notify("docbase", "openBuffer", ["PostList", {"domain": a:domain}, a:mods]) | ||
endfunction | ||
|
||
function! docbase#open#post(domain, post_id, opener="edit") | ||
call denops#notify("docbase", "openBuffer", ["Post", {"domain": a:domain,"postId": a:post_id}, a:opener]) | ||
function! docbase#open#post(domain, post_id, mods="") | ||
call denops#notify("docbase", "openBuffer", ["Post", {"domain": a:domain,"postId": a:post_id}, a:mods]) | ||
endfunction | ||
|
||
function! docbase#open#new_post(domain, opener="edit") | ||
call denops#notify("docbase", "openBuffer", ["NewPost", {"domain": a:domain}, a:opener]) | ||
function! docbase#open#new_post(domain, mods="") | ||
call denops#notify("docbase", "openBuffer", ["NewPost", {"domain": a:domain}, a:mods]) | ||
endfunction | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,7 +11,7 @@ import { | |
maybe, | ||
} from "https://deno.land/x/[email protected]/mod.ts"; | ||
|
||
import { isOpener, isPost } from "../types.ts"; | ||
import { isPost } from "../types.ts"; | ||
import { Filetype, prepareViewer, setViewerContent } from "./buffer.ts"; | ||
import { Handler, openBuffer } from "../router.ts"; | ||
import type { Context, Params } from "../router.ts"; | ||
|
@@ -86,7 +86,7 @@ export const PostList: Handler = { | |
async open(denops: Denops, _context: Context, _params: Params) { | ||
const params = ensure( | ||
_params, | ||
is.ObjectOf({ lnum: is.Number, opener: is.OptionalOf(isOpener) }), | ||
is.ObjectOf({ lnum: is.Number, mods: is.OptionalOf(is.String) }), | ||
); | ||
const domain = ensure( | ||
await variable.b.get(denops, "docbase_posts_list_domain"), | ||
|
@@ -102,7 +102,7 @@ export const PostList: Handler = { | |
await openBuffer(denops, "Post", { | ||
domain, | ||
postId: String(postIds[params.lnum - 1]), | ||
}, params.opener); | ||
}, params.mods); | ||
}, | ||
prev(denops: Denops, context: Context, _params: Params) { | ||
return paging(denops, context, -1); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,6 @@ import * as variable from "https://deno.land/x/[email protected]/variable/variab | |
import { Filetype, prepareViewer, setViewerContent } from "./buffer.ts"; | ||
import { Handler, openBuffer } from "../router.ts"; | ||
import type { Context, Params } from "../router.ts"; | ||
import { isOpener } from "../types.ts"; | ||
|
||
const pattern = new URLPattern({ | ||
hostname: "teams", | ||
|
@@ -39,7 +38,7 @@ export const TeamList: Handler = { | |
async open(denops: Denops, _context: Context, _params: Params) { | ||
const params = ensure( | ||
_params, | ||
is.ObjectOf({ lnum: is.Number, opener: is.OptionalOf(isOpener) }), | ||
is.ObjectOf({ lnum: is.Number, mods: is.OptionalOf(is.String) }), | ||
); | ||
const domains = ensure( | ||
await variable.b.get( | ||
|
@@ -52,7 +51,7 @@ export const TeamList: Handler = { | |
denops, | ||
"PostList", | ||
{ domain: domains[params.lnum - 1] }, | ||
params.opener, | ||
params.mods, | ||
); | ||
}, | ||
}, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,7 +14,7 @@ import { | |
setup, | ||
} from "https://deno.land/[email protected]/log/mod.ts"; | ||
|
||
import { isOpener, isSearchPostsParams } from "./types.ts"; | ||
import { isSearchPostsParams } from "./types.ts"; | ||
import { Client } from "./api/client.ts"; | ||
import { bufferAction, bufferLoaded, openBuffer } from "./router.ts"; | ||
import { XDGStateMan } from "./state.ts"; | ||
|
@@ -46,12 +46,12 @@ export async function main(denops: Denops) { | |
}); | ||
|
||
denops.dispatcher = { | ||
async openBuffer(uHandler: unknown, uProps: unknown, uOpener: unknown) { | ||
async openBuffer(uHandler: unknown, uProps: unknown, uMods: unknown) { | ||
try { | ||
const handler = ensure(uHandler, is.String); | ||
const props = ensure(uProps, is.Record); | ||
const opener = ensure(uOpener, is.OptionalOf(isOpener)); | ||
await openBuffer(denops, handler, props, opener); | ||
const mods = ensure(uMods, is.OptionalOf(is.String)); | ||
await openBuffer(denops, handler, props, mods); | ||
} catch (err) { | ||
getLogger("denops-docbase").error(err); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
import type { Denops } from "https://deno.land/x/[email protected]/mod.ts"; | ||
import * as fn from "https://deno.land/x/[email protected]/function/mod.ts"; | ||
|
||
import type { Opener } from "./types.ts"; | ||
import type { StateMan } from "./state.ts"; | ||
import { TeamList } from "./handler/teams_list.ts"; | ||
import { PostList } from "./handler/posts_list.ts"; | ||
|
@@ -45,18 +44,54 @@ function routing(bufname: string) { | |
throw new Error(`There's no valid handler for ${bufname}`); | ||
} | ||
|
||
function modsOpener(mods: string): string { | ||
for (const mod of mods.split(/\s+/).reverse()) { | ||
switch (mod) { | ||
case "vert": | ||
return "vnew"; | ||
case "verti": | ||
return "vnew"; | ||
case "vertic": | ||
return "vnew"; | ||
case "vertica": | ||
return "vnew"; | ||
case "vertical": | ||
return "vnew"; | ||
case "hor": | ||
return "new"; | ||
case "hori": | ||
return "new"; | ||
case "horiz": | ||
return "new"; | ||
case "horizo": | ||
return "new"; | ||
case "horizon": | ||
return "new"; | ||
case "horizont": | ||
return "new"; | ||
case "horizonta": | ||
return "new"; | ||
case "horizontal": | ||
return "new"; | ||
case "tab": | ||
return "tabnew"; | ||
} | ||
} | ||
return "edit"; | ||
} | ||
export async function openBuffer( | ||
denops: Denops, | ||
handler: string, | ||
props: Record<string, unknown>, | ||
opener: Opener = "edit", | ||
mods: string = "", | ||
) { | ||
const h = handlers[handler]; | ||
if (!h) { | ||
throw new Error(`There's no handler ${handler}`); | ||
} | ||
const bufname = h.bufname(props); | ||
await denops.cmd(`${opener} ${bufname}`); | ||
const opener = modsOpener(mods); | ||
await denops.cmd(`${mods} ${opener} ${bufname}`); | ||
} | ||
|
||
export async function bufferLoaded( | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,2 @@ | ||
import { | ||
is, | ||
// ObjectOf as O, | ||
Predicate as P, | ||
} from "https://deno.land/x/[email protected]/mod.ts"; | ||
|
||
export type Opener = "edit" | "new" | "vnew" | "tabnew"; | ||
export const isOpener: P<Opener> = is.OneOf([ | ||
is.LiteralOf("edit"), | ||
is.LiteralOf("new"), | ||
is.LiteralOf("vnew"), | ||
is.LiteralOf("tabnew"), | ||
]); | ||
|
||
export * from "./api/types.ts"; | ||
export * from "./api/validation.ts"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
nnoremap <buffer> <plug>(docbase-buffer-action-posts-list-open) <cmd>call docbase#buffer_action#posts_list#open(line(".")) | ||
nnoremap <buffer> <plug>(docbase-buffer-action-posts-list-open-new) <cmd>call docbase#buffer_action#posts_list#open(line("."), "new") | ||
nnoremap <buffer> <plug>(docbase-buffer-action-posts-list-open-vnew) <cmd>call docbase#buffer_action#posts_list#open(line("."), "vnew") | ||
nnoremap <buffer> <plug>(docbase-buffer-action-posts-list-open-tabedit) <cmd>call docbase#buffer_action#posts_list#open(line("."), "tabedit") | ||
nnoremap <buffer> <plug>(docbase-buffer-action-posts-list-open) <cmd>call docbase#buffer_action#posts_list#open(line("."), "") | ||
nnoremap <buffer> <plug>(docbase-buffer-action-posts-list-open-new) <cmd>call docbase#buffer_action#posts_list#open(line("."), "horizontal") | ||
nnoremap <buffer> <plug>(docbase-buffer-action-posts-list-open-vnew) <cmd>call docbase#buffer_action#posts_list#open(line("."), "vertical") | ||
nnoremap <buffer> <plug>(docbase-buffer-action-posts-list-open-tabedit) <cmd>call docbase#buffer_action#posts_list#open(line("."), "tab") | ||
nnoremap <buffer> <plug>(docbase-buffer-action-posts-list-prev) <cmd>call docbase#buffer_action#posts_list#prev() | ||
nnoremap <buffer> <plug>(docbase-buffer-action-posts-list-next) <cmd>call docbase#buffer_action#posts_list#next() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
nnoremap <buffer> <plug>(docbase-buffer-action-teams-list-open) <cmd>call docbase#buffer_action#teams_list#open(line(".")) | ||
nnoremap <buffer> <plug>(docbase-buffer-action-teams-list-open-new) <cmd>call docbase#buffer_action#teams_list#open(line("."), "new") | ||
nnoremap <buffer> <plug>(docbase-buffer-action-teams-list-open-vnew) <cmd>call docbase#buffer_action#teams_list#open(line("."), "vnew") | ||
nnoremap <buffer> <plug>(docbase-buffer-action-teams-list-open-tabedit) <cmd>call docbase#buffer_action#teams_list#open(line("."), "tabedit") | ||
nnoremap <buffer> <plug>(docbase-buffer-action-teams-list-open) <cmd>call docbase#buffer_action#teams_list#open(line("."), "") | ||
nnoremap <buffer> <plug>(docbase-buffer-action-teams-list-open-new) <cmd>call docbase#buffer_action#teams_list#open(line("."), "horizontal") | ||
nnoremap <buffer> <plug>(docbase-buffer-action-teams-list-open-vnew) <cmd>call docbase#buffer_action#teams_list#open(line("."), "vertical") | ||
nnoremap <buffer> <plug>(docbase-buffer-action-teams-list-open-tabedit) <cmd>call docbase#buffer_action#teams_list#open(line("."), "tab") |