Skip to content

Commit

Permalink
feat: support sound for button click and some accept completion
Browse files Browse the repository at this point in the history
  • Loading branch information
oeyoews committed Oct 1, 2024
1 parent 69c75a0 commit 7d34a9b
Show file tree
Hide file tree
Showing 16 changed files with 61 additions and 8 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"registry": "https://registry.npmjs.org"
},
"license": "MIT",
"version": "2.1.2",
"version": "2.2.0",
"packageManager": "pnpm@9.0.6",
"scripts": {
"update:config": " pnpm ts-node scripts/generateConfig.ts",
Expand Down
3 changes: 2 additions & 1 deletion src/tiddlywiki-cmp/plugin.info
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
"qrcode": "yes",
"created": "2024-01-05",
"dependents": [
"$:/plugins/oeyoews/tiddlywiki-codemirror-6"
"$:/plugins/oeyoews/tiddlywiki-codemirror-6",
"$:/plugins/oeyoews/neotw-play-sound"
],
"list": "readme"
}
11 changes: 11 additions & 0 deletions src/tiddlywiki-codemirror-6/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,17 @@ function defineConfig<T extends Object, K extends keyof T>(

// #region tiddlers
export const tiddlers = defineConfig({
useSound: {
caption: {
zh: '使用声音',
en: 'Use Sound'
},
text: 'no',
description: {
zh: '插件neotw-play-sound提供声音支持',
en: 'Use Sound'
}
},
insertModeFirst: {
caption: {
zh: 'VIM自动进入插入模式',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
} from '@codemirror/autocomplete';
import { delimitersInfo } from '.';
import { IWidget } from '@/cm6/types/IWidget';
import { useSound } from '@/cm6/utils/capitalize';

const section = 'help';
const type = 'cm-help';
Expand All @@ -29,6 +30,7 @@ function snippets(widget: IWidget): Completion[] {
view.dispatch({
changes: { from, to, insert: item.delimiter }
});
useSound();
startCompletion(view);
},
type: item.type
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,5 +119,6 @@ export default {
section,
type,
delimiter,
description,
snippets
};
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Completion } from '@codemirror/autocomplete';
import conf from '@/cm6/config';
import { renderTid } from '@/cm6/utils/renderTiddler';
import { EditorView } from '@codemirror/view';
import { useSound } from '@/cm6/utils/capitalize';

const type = 'cm-tiddler';
const section = 'tiddlers';
Expand Down Expand Up @@ -40,6 +41,7 @@ export function getAllTiddlers(delimiter: string) {
changes: { from, to, insert: delimiter + title },
selection: { anchor: cursorEndPosition, head: cursorEndPosition }
});
useSound();
}
}) as Completion
);
Expand Down
2 changes: 2 additions & 0 deletions src/tiddlywiki-codemirror-6/modules/extensions/tidExt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
} from '@codemirror/view';
import cm6 from '@/cm6/config';
import createViewPlugin from '@/cm6/utils/createViewPlugin';
import { useSound } from '@/cm6/utils/capitalize';

class CustomLink extends WidgetType {
constructor(state) {
Expand All @@ -32,6 +33,7 @@ class CustomLink extends WidgetType {
wrapper.onclick = (e: MouseEvent) => {
e.preventDefault();
if (e.ctrlKey) {
useSound();
new $tw.Story().navigateTiddler(title);
}
};
Expand Down
2 changes: 2 additions & 0 deletions src/tiddlywiki-codemirror-6/modules/extensions/wordhover.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { useSound } from '@/cm6/utils/capitalize';
import { type Extension } from '@codemirror/state';
import { hoverTooltip, EditorView } from '@codemirror/view';

Expand Down Expand Up @@ -56,6 +57,7 @@ export const wordHover: Extension = hoverTooltip(
dom.addEventListener('click', (e: MouseEvent) => {
e.preventDefault();
if (e.ctrlKey) {
useSound();
dom.hidden = true; // 隐藏弹窗
new $tw.Story().navigateTiddler(title);
}
Expand Down
4 changes: 2 additions & 2 deletions src/tiddlywiki-codemirror-6/plugin.info
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"title": "$:/plugins/oeyoews/tiddlywiki-codemirror-6",
"name": "CodeMirror6",
"description": "CodeMirror 6 editor",
"version": "2.1.2",
"core-version": ">=5.3.3",
"version": "2.2.0",
"core-version": ">=5.3.4",
"list": "readme usage"
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
title: $:/language/codemirror6/

useSound/caption: 📝 Use Sound
useSound/description: Use Sound
insertModeFirst/caption: 📝 Insert Mode Auto Firstly
insertModeFirst/description: Insert Mode Auto Firstly
lines/caption: 📝 Lines
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
title: $:/language/codemirror6/zh/

useSound/caption: 📝 使用声音
useSound/description: 插件neotw-play-sound提供声音支持
insertModeFirst/caption: 📝 VIM自动进入插入模式
insertModeFirst/description: VIM自动进入插入模式
lines/caption: 📝 自动生成行数
lines/description: 新建tiddler自动生成N行
todobox/caption: 📝 代办事项复选框(MD)
todobox/description: 代办事项复选框(MD)
checkbox/caption: 📝 复选框(JS)
checkbox/description: 复选框(JS)
checkbox/description: 适用于tiddler类型为javascript, 用于切换常量的布尔值, 普通用户建议关闭
foldByIndent/caption: 📝 按缩进折叠
foldByIndent/description: 按缩进折叠
removeOutline/caption: 📝 移除编辑器边框
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ description: {{$:/language/codemirror6/lineWrapping/description}}
description-zh: {{$:/language/codemirror6/zh/lineWrapping/description}}
settings-template: $:/plugins/oeyoews/tiddlywiki-codemirror-6/ui/templates/settings/input-switch

no
yes
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
title: $:/config/codemirror-6/useSound
caption: {{$:/language/codemirror6/useSound/caption}}
caption-zh: {{$:/language/codemirror6/zh/useSound/caption}}
description: {{$:/language/codemirror6/useSound/description}}
description-zh: {{$:/language/codemirror6/zh/useSound/description}}
settings-template: $:/plugins/oeyoews/tiddlywiki-codemirror-6/ui/templates/settings/input-switch

no
2 changes: 1 addition & 1 deletion src/tiddlywiki-codemirror-6/tiddlers/styles/styles.tid
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ body {
height: 100vh;
width: 100vw;
<!-- z-index: 1000; prevent autocomplete not visible -->
z-index: 1;
z-index: 999;
}

.tc-tiddler-edit-frame[data-tiddler-title="$(cssEscapedTitle)$"] .tc-dropzone-editor {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
title: $:/plugins/oeyoews/tiddlywiki-codemirror-6/ui/templates/settings/input-switch

\define useSound()
<$action-sendmessage $message="neotw-play-sound" audioTiddler="$:/plugins/oeyoews/neotw-play-sound/sounds/bite.mp3" />
\end

<!-- NOTE: check 不会即使更新shadow tiddler -->
<label class="btcui-form-label">

Expand All @@ -23,4 +27,8 @@ title: $:/plugins/oeyoews/tiddlywiki-codemirror-6/ui/templates/settings/input-sw

</label>

<$checkbox field="text" checked="yes" unchecked="no" class="btcui-form-switch"/>
<% if [[$:/config/codemirror-6/useSound]get[text]match[yes]] %>
<$checkbox field="text" checked="yes" unchecked="no" class="btcui-form-switch" actions=<<useSound>>/>
<% else %>
<$checkbox field="text" checked="yes" unchecked="no" class="btcui-form-switch"/>
<% endif %>
12 changes: 12 additions & 0 deletions src/tiddlywiki-codemirror-6/utils/capitalize.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,16 @@
import cm6 from '../config';

// equal to $tw.utils.toTitleCase
export function capitalize(str: string) {
return str.replace(/^\w/, (match) => match.toUpperCase());
}

export function useSound() {
if (!cm6.useSound()) return;
$tw.rootWidget.dispatchEvent({
type: 'neotw-play-sound',
paramObject: {
audioTiddler: '$:/plugins/oeyoews/neotw-play-sound/sounds/bite.mp3'
}
});
}

0 comments on commit 7d34a9b

Please sign in to comment.