Removed status bar, replaced with `Show: Stats` command
parent
525b30c9bb
commit
ec7c272594
|
@ -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<void>) {
|
export function safeRun(fn: () => Promise<void>) {
|
||||||
fn().catch((e) => {
|
fn().catch((e) => {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
|
|
|
@ -342,3 +342,11 @@ functions:
|
||||||
path: ./link.ts:titleUnfurl
|
path: ./link.ts:titleUnfurl
|
||||||
events:
|
events:
|
||||||
- unfurl:title-unfurl
|
- unfurl:title-unfurl
|
||||||
|
|
||||||
|
# Random stuff
|
||||||
|
statsCommand:
|
||||||
|
path: ./stats.ts:statsCommand
|
||||||
|
command:
|
||||||
|
name: "Stats: Show"
|
||||||
|
key: "Ctrl-Shift-s"
|
||||||
|
mac: "Cmd-Shift-s"
|
||||||
|
|
|
@ -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.`);
|
||||||
|
}
|
|
@ -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 (
|
|
||||||
<div id="sb-status-bar">
|
|
||||||
<div className="inner">
|
|
||||||
{wordCount} words | {readingTime} min
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
|
@ -50,7 +50,6 @@ import { SlashCommandHook } from "./hooks/slash_command";
|
||||||
import { pasteLinkExtension } from "./editor_paste";
|
import { pasteLinkExtension } from "./editor_paste";
|
||||||
import { markdownSyscalls } from "@silverbulletmd/common/syscalls/markdown";
|
import { markdownSyscalls } from "@silverbulletmd/common/syscalls/markdown";
|
||||||
import { clientStoreSyscalls } from "./syscalls/clientStore";
|
import { clientStoreSyscalls } from "./syscalls/clientStore";
|
||||||
import { StatusBar } from "./components/status_bar";
|
|
||||||
import {
|
import {
|
||||||
loadMarkdownExtensions,
|
loadMarkdownExtensions,
|
||||||
MDExt,
|
MDExt,
|
||||||
|
@ -758,7 +757,6 @@ export class Editor {
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
<StatusBar editorView={editor.editorView} />
|
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -67,7 +67,7 @@
|
||||||
.notifications {
|
.notifications {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
font-family: "iA-Mono";
|
font-family: "iA-Mono";
|
||||||
bottom: 45px;
|
bottom: 0;
|
||||||
left: 5px;
|
left: 5px;
|
||||||
right: 5px;
|
right: 5px;
|
||||||
font-size: 15px;
|
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";
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in New Issue