mirror of
https://github.com/purocean/yn.git
synced 2026-10-16 07:26:07 +08:00
feat: add typewriter mode
This commit is contained in:
@@ -39,6 +39,7 @@ export default defineComponent({
|
||||
'edit-solid': '<svg aria-hidden="true" focusable="false" data-prefix="fas" data-icon="edit" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 576 512" class="svg-inline--fa fa-edit fa-w-18"><path fill="currentColor" d="M402.6 83.2l90.2 90.2c3.8 3.8 3.8 10 0 13.8L274.4 405.6l-92.8 10.3c-12.4 1.4-22.9-9.1-21.5-21.5l10.3-92.8L388.8 83.2c3.8-3.8 10-3.8 13.8 0zm162-22.9l-48.8-48.8c-15.2-15.2-39.9-15.2-55.2 0l-35.4 35.4c-3.8 3.8-3.8 10 0 13.8l90.2 90.2c3.8 3.8 10 3.8 13.8 0l35.4-35.4c15.2-15.3 15.2-40 0-55.2zM384 346.2V448H64V128h229.8c3.2 0 6.2-1.3 8.5-3.5l40-40c7.6-7.6 2.2-20.5-8.5-20.5H48C21.5 64 0 85.5 0 112v352c0 26.5 21.5 48 48 48h352c26.5 0 48-21.5 48-48V306.2c0-10.7-12.9-16-20.5-8.5l-40 40c-2.2 2.3-3.5 5.3-3.5 8.5z" class=""></path></svg>',
|
||||
'eye-regular': '<svg aria-hidden="true" focusable="false" data-prefix="far" data-icon="eye" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 576 512" class="svg-inline--fa fa-eye fa-w-18"><path fill="currentColor" d="M288 144a110.94 110.94 0 0 0-31.24 5 55.4 55.4 0 0 1 7.24 27 56 56 0 0 1-56 56 55.4 55.4 0 0 1-27-7.24A111.71 111.71 0 1 0 288 144zm284.52 97.4C518.29 135.59 410.93 64 288 64S57.68 135.64 3.48 241.41a32.35 32.35 0 0 0 0 29.19C57.71 376.41 165.07 448 288 448s230.32-71.64 284.52-177.41a32.35 32.35 0 0 0 0-29.19zM288 400c-98.65 0-189.09-55-237.93-144C98.91 167 189.34 112 288 112s189.09 55 237.93 144C477.1 345 386.66 400 288 400z" class=""></path></svg>',
|
||||
'text-width-solid': '<svg aria-hidden="true" focusable="false" data-prefix="fas" data-icon="text-width" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512" class="svg-inline--fa fa-text-width fa-w-14"><path fill="currentColor" d="M432 32H16A16 16 0 0 0 0 48v80a16 16 0 0 0 16 16h32a16 16 0 0 0 16-16v-16h120v112h-24a16 16 0 0 0-16 16v32a16 16 0 0 0 16 16h128a16 16 0 0 0 16-16v-32a16 16 0 0 0-16-16h-24V112h120v16a16 16 0 0 0 16 16h32a16 16 0 0 0 16-16V48a16 16 0 0 0-16-16zm-68.69 260.69C354 283.36 336 288.36 336 304v48H112v-48c0-14.31-17.31-21.32-27.31-11.31l-80 80a16 16 0 0 0 0 22.62l80 80C94 484.64 112 479.64 112 464v-48h224v48c0 14.31 17.31 21.33 27.31 11.31l80-80a16 16 0 0 0 0-22.62z" class=""></path></svg>',
|
||||
'keyboard-solid': '<svg aria-hidden="true" focusable="false" data-prefix="fas" data-icon="keyboard" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 576 512" class="svg-inline--fa fa-keyboard fa-w-18"><path fill="currentColor" d="M528 448H48c-26.51 0-48-21.49-48-48V112c0-26.51 21.49-48 48-48h480c26.51 0 48 21.49 48 48v288c0 26.51-21.49 48-48 48zM128 180v-40c0-6.627-5.373-12-12-12H76c-6.627 0-12 5.373-12 12v40c0 6.627 5.373 12 12 12h40c6.627 0 12-5.373 12-12zm96 0v-40c0-6.627-5.373-12-12-12h-40c-6.627 0-12 5.373-12 12v40c0 6.627 5.373 12 12 12h40c6.627 0 12-5.373 12-12zm96 0v-40c0-6.627-5.373-12-12-12h-40c-6.627 0-12 5.373-12 12v40c0 6.627 5.373 12 12 12h40c6.627 0 12-5.373 12-12zm96 0v-40c0-6.627-5.373-12-12-12h-40c-6.627 0-12 5.373-12 12v40c0 6.627 5.373 12 12 12h40c6.627 0 12-5.373 12-12zm96 0v-40c0-6.627-5.373-12-12-12h-40c-6.627 0-12 5.373-12 12v40c0 6.627 5.373 12 12 12h40c6.627 0 12-5.373 12-12zm-336 96v-40c0-6.627-5.373-12-12-12h-40c-6.627 0-12 5.373-12 12v40c0 6.627 5.373 12 12 12h40c6.627 0 12-5.373 12-12zm96 0v-40c0-6.627-5.373-12-12-12h-40c-6.627 0-12 5.373-12 12v40c0 6.627 5.373 12 12 12h40c6.627 0 12-5.373 12-12zm96 0v-40c0-6.627-5.373-12-12-12h-40c-6.627 0-12 5.373-12 12v40c0 6.627 5.373 12 12 12h40c6.627 0 12-5.373 12-12zm96 0v-40c0-6.627-5.373-12-12-12h-40c-6.627 0-12 5.373-12 12v40c0 6.627 5.373 12 12 12h40c6.627 0 12-5.373 12-12zm-336 96v-40c0-6.627-5.373-12-12-12H76c-6.627 0-12 5.373-12 12v40c0 6.627 5.373 12 12 12h40c6.627 0 12-5.373 12-12zm288 0v-40c0-6.627-5.373-12-12-12H172c-6.627 0-12 5.373-12 12v40c0 6.627 5.373 12 12 12h232c6.627 0 12-5.373 12-12zm96 0v-40c0-6.627-5.373-12-12-12h-40c-6.627 0-12 5.373-12 12v40c0 6.627 5.373 12 12 12h40c6.627 0 12-5.373 12-12z" class=""></path></svg>',
|
||||
}
|
||||
|
||||
const name = props.name!
|
||||
|
||||
@@ -46,6 +46,18 @@ export default {
|
||||
ctx.layout.toggleView()
|
||||
}
|
||||
},
|
||||
{
|
||||
type: 'btn',
|
||||
icon: 'paint-roller',
|
||||
title: ctx.i18n.t('control-center.switch.sync-rendering'),
|
||||
checked: ctx.store.state.autoPreview,
|
||||
onClick: () => {
|
||||
ctx.view.toggleAutoPreview()
|
||||
if (ctx.store.state.autoPreview) {
|
||||
ctx.view.refresh()
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
type: 'btn',
|
||||
icon: 'text-width-solid',
|
||||
@@ -57,14 +69,11 @@ export default {
|
||||
},
|
||||
{
|
||||
type: 'btn',
|
||||
icon: 'paint-roller',
|
||||
title: ctx.i18n.t('control-center.switch.sync-rendering'),
|
||||
checked: ctx.store.state.autoPreview,
|
||||
icon: 'keyboard-solid',
|
||||
title: ctx.i18n.t('control-center.switch.typewriter-mode'),
|
||||
checked: ctx.store.state.typewriterMode,
|
||||
onClick: () => {
|
||||
ctx.view.toggleAutoPreview()
|
||||
if (ctx.store.state.autoPreview) {
|
||||
ctx.view.refresh()
|
||||
}
|
||||
ctx.editor.toggleTypewriterMode()
|
||||
}
|
||||
},
|
||||
)
|
||||
|
||||
@@ -234,6 +234,10 @@ export function toggleWrap () {
|
||||
store.commit('setWordWrap', (isWrapping ? 'off' : 'on'))
|
||||
}
|
||||
|
||||
export function toggleTypewriterMode () {
|
||||
store.commit('setTypewriterMode', !store.state.typewriterMode)
|
||||
}
|
||||
|
||||
registerAction({ name: 'editor.toggle-wrap', handler: toggleWrap, keys: [Alt, 'w'] })
|
||||
|
||||
registerHook('MONACO_BEFORE_INIT', ({ monaco }) => {
|
||||
@@ -282,3 +286,15 @@ store.watch(state => state.wordWrap, (wordWrap) => {
|
||||
editor.updateOptions({ wordWrap })
|
||||
})
|
||||
})
|
||||
|
||||
whenEditorReady().then(({ editor }) => {
|
||||
// typewriter mode
|
||||
editor.onDidChangeCursorPosition(e => {
|
||||
if (store.state.typewriterMode) {
|
||||
const sources = ['deleteLeft', 'keyboard']
|
||||
if (sources.includes(e.source) && e.reason === 0) {
|
||||
editor.revealPositionInCenter(e.position)
|
||||
}
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
@@ -6,6 +6,7 @@ import type { Components, Doc, Repo } from '@fe/types'
|
||||
export const initState = {
|
||||
tree: null,
|
||||
wordWrap: storage.get<'off' | 'on'>('wordWrap', 'off'),
|
||||
typewriterMode: storage.get<boolean>('typewriterMode', false),
|
||||
showSide: storage.get('showSide', true),
|
||||
showView: storage.get('showView', true),
|
||||
showEditor: storage.get('showEditor', true),
|
||||
@@ -42,6 +43,10 @@ export default createStore({
|
||||
state.wordWrap = data
|
||||
storage.set('wordWrap', data)
|
||||
},
|
||||
setTypewriterMode (state, data: boolean) {
|
||||
state.typewriterMode = data
|
||||
storage.set('typewriterMode', data)
|
||||
},
|
||||
setShowView (state, data) {
|
||||
state.showView = data
|
||||
storage.set('showView', data)
|
||||
|
||||
@@ -411,8 +411,9 @@ const data = {
|
||||
'side-bar': 'Side Bar %s',
|
||||
'editor': 'Editor %s',
|
||||
'view': 'Editor %s',
|
||||
'word-wrap': 'Word Wrap %s',
|
||||
'sync-rendering': 'Synchronous rendering',
|
||||
'word-wrap': 'Word Wrap %s',
|
||||
'typewriter-mode': 'Typewriter Mode',
|
||||
},
|
||||
'navigation': {
|
||||
'goto': 'Goto %s',
|
||||
|
||||
@@ -412,8 +412,9 @@ const data: BaseLanguage = {
|
||||
'side-bar': '侧栏 %s',
|
||||
'editor': '编辑器 %s',
|
||||
'view': '预览 %s',
|
||||
'word-wrap': '编辑器换行 %s',
|
||||
'sync-rendering': '同步渲染',
|
||||
'word-wrap': '编辑器换行 %s',
|
||||
'typewriter-mode': '打字机模式',
|
||||
},
|
||||
'navigation': {
|
||||
'goto': '跳转 %s',
|
||||
|
||||
Reference in New Issue
Block a user