diff --git a/packages/common/util.ts b/packages/common/util.ts index 1e73f0d6..5f8b3ddd 100644 --- a/packages/common/util.ts +++ b/packages/common/util.ts @@ -1,13 +1,3 @@ -export function countWords(str: string): number { - const matches = str.match(/[\w\d\'-]+/gi); - return matches ? matches.length : 0; -} - -export function readingTime(wordCount: number): number { - // 225 is average word reading speed for adults - return Math.ceil(wordCount / 225); -} - export function safeRun(fn: () => Promise) { fn().catch((e) => { console.error(e); diff --git a/packages/plugs/core/core.plug.yaml b/packages/plugs/core/core.plug.yaml index 0862bde7..6cf571ec 100644 --- a/packages/plugs/core/core.plug.yaml +++ b/packages/plugs/core/core.plug.yaml @@ -342,3 +342,11 @@ functions: path: ./link.ts:titleUnfurl events: - unfurl:title-unfurl + + # Random stuff + statsCommand: + path: ./stats.ts:statsCommand + command: + name: "Stats: Show" + key: "Ctrl-Shift-s" + mac: "Cmd-Shift-s" diff --git a/packages/plugs/core/stats.ts b/packages/plugs/core/stats.ts new file mode 100644 index 00000000..737b84a5 --- /dev/null +++ b/packages/plugs/core/stats.ts @@ -0,0 +1,21 @@ +import { + flashNotification, + getText, +} from "@silverbulletmd/plugos-silverbullet-syscall/editor"; + +function countWords(str: string): number { + const matches = str.match(/[\w\d\'-]+/gi); + return matches ? matches.length : 0; +} + +function readingTime(wordCount: number): number { + // 225 is average word reading speed for adults + return Math.ceil(wordCount / 225); +} + +export async function statsCommand() { + const text = await getText(); + const wordCount = countWords(text); + const time = readingTime(wordCount); + await flashNotification(`${wordCount} words, ${time} minutes to read.`); +} diff --git a/packages/web/components/status_bar.tsx b/packages/web/components/status_bar.tsx deleted file mode 100644 index d9a14cb9..00000000 --- a/packages/web/components/status_bar.tsx +++ /dev/null @@ -1,19 +0,0 @@ -import { EditorView } from "@codemirror/view"; -import * as util from "../../common/util"; - -export function StatusBar({ editorView }: { editorView?: EditorView }) { - let wordCount = 0, - readingTime = 0; - if (editorView) { - let text = editorView.state.sliceDoc(); - wordCount = util.countWords(text); - readingTime = util.readingTime(wordCount); - } - return ( -
-
- {wordCount} words | {readingTime} min -
-
- ); -} diff --git a/packages/web/editor.tsx b/packages/web/editor.tsx index f931d208..3312ebd3 100644 --- a/packages/web/editor.tsx +++ b/packages/web/editor.tsx @@ -50,7 +50,6 @@ import { SlashCommandHook } from "./hooks/slash_command"; import { pasteLinkExtension } from "./editor_paste"; import { markdownSyscalls } from "@silverbulletmd/common/syscalls/markdown"; import { clientStoreSyscalls } from "./syscalls/clientStore"; -import { StatusBar } from "./components/status_bar"; import { loadMarkdownExtensions, MDExt, @@ -758,7 +757,6 @@ export class Editor { /> )} - ); } diff --git a/packages/web/styles/main.scss b/packages/web/styles/main.scss index c0e7d454..eed9627c 100644 --- a/packages/web/styles/main.scss +++ b/packages/web/styles/main.scss @@ -67,7 +67,7 @@ .notifications { position: absolute; font-family: "iA-Mono"; - bottom: 45px; + bottom: 0; left: 5px; right: 5px; font-size: 15px; @@ -171,13 +171,3 @@ } } } - -#sb-status-bar { - height: 40px; - line-height: 40px; - padding: 0 10px; - text-align: right; - background-color: rgb(213, 213, 213); - border-top: rgb(193, 193, 193) 1px solid; - font-family: "iA-Mono"; -}