Skip to content

Commit

Permalink
add vim bindings if user already has vim mode enabled in obsidian
Browse files Browse the repository at this point in the history
  • Loading branch information
GamerGirlandCo committed Nov 3, 2024
1 parent f1f0210 commit 9840d29
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 1 deletion.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
"@fortawesome/fontawesome-svg-core": "^6.4.0",
"@fortawesome/free-solid-svg-icons": "^6.4.0",
"@fortawesome/react-fontawesome": "^0.2.0",
"@replit/codemirror-vim": "^6.2.1",
"codemirror": "^6.0.1",
"emoji-regex": "^10.2.1",
"flatqueue": "^2.0.3",
Expand Down
3 changes: 3 additions & 0 deletions src/typings/obsidian-ex.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ declare module "obsidian" {
};
};
}
interface Vault {
getConfig: (conf: string) => any;
}
interface App {
appId?: string;
plugins: {
Expand Down
6 changes: 5 additions & 1 deletion src/ui/view-page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import {
import { tagHighlighter, tags } from "@lezer/highlight";
import { javascript } from "@codemirror/lang-javascript";
import { EditorState } from "@codemirror/state";
import { vim } from "@replit/codemirror-vim";

/** Key for datacore JS query views. */
export const VIEW_TYPE_DATACOREJS = "datacorejs-view";
Expand Down Expand Up @@ -204,6 +205,8 @@ function CodeMirrorEditor({
}) {
const editorRef = useRef<HTMLDivElement>(null);
const viewRef = useRef<EditorView>(null);
const viewContext = useContext(CUSTOM_VIEW_CONTEXT);

const langMode = useMemo(() => {
switch (lang) {
case "jsx":
Expand Down Expand Up @@ -235,7 +238,8 @@ function CodeMirrorEditor({
}
),
EDITOR_HL,
],
viewContext.app.vault.getConfig("vimMode") && vim(),
].filter((a) => !!a),
doc: script || "",
});
return () => viewRef.current?.destroy();
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -914,6 +914,11 @@
resolved "https://registry.yarnpkg.com/@pkgjs/parseargs/-/parseargs-0.11.0.tgz#a77ea742fab25775145434eb1d2328cf5013ac33"
integrity sha512-+1VkjdD0QBLPodGrJUeqarH8VAIvQODIbwh9XpP5Syisf7YoQgsJKPNFoqqLQlu+VQ/tVSshMR6loPMn8U+dPg==

"@replit/codemirror-vim@^6.2.1":
version "6.2.1"
resolved "https://registry.yarnpkg.com/@replit/codemirror-vim/-/codemirror-vim-6.2.1.tgz#6673ff4be93b7da03d303ef37d6cbfa5f647b74b"
integrity sha512-qDAcGSHBYU5RrdO//qCmD8K9t6vbP327iCj/iqrkVnjbrpFhrjOt92weGXGHmTNRh16cUtkUZ7Xq7rZf+8HVow==

"@sinonjs/commons@^1.7.0":
version "1.8.6"
resolved "https://registry.yarnpkg.com/@sinonjs/commons/-/commons-1.8.6.tgz#80c516a4dc264c2a69115e7578d62581ff455ed9"
Expand Down

0 comments on commit 9840d29

Please sign in to comment.