1+ import { goToSnippet } from '@/composable'
12import { platform , store } from '@/electron'
23import type { MarkdownSettings } from '@shared/types/main/store'
34import type {
@@ -39,6 +40,8 @@ const MARKDOWN_DEFAULTS: MarkdownSettings = {
3940 codeRenderer : 'highlight.js'
4041}
4142
43+ const HISTORY_LIMIT = 50
44+
4245export const useAppStore = defineStore ( 'app' , {
4346 state : ( ) : State => ( {
4447 isInit : false ,
@@ -64,6 +67,8 @@ export const useAppStore = defineStore('app', {
6467 markdown : MARKDOWN_DEFAULTS ,
6568 selectedPreferencesMenu : 'storage' ,
6669 language : store . preferences . get ( 'language' ) ,
70+ history : [ ] ,
71+ historyIndex : 0 ,
6772 version,
6873 platform : platform ( )
6974 } ) ,
@@ -91,6 +96,27 @@ export const useAppStore = defineStore('app', {
9196 setLang ( lang : string ) {
9297 this . language = lang
9398 store . preferences . set ( 'language' , lang )
99+ } ,
100+ addToHistory ( snippetId : string ) {
101+ if ( ! snippetId ) return
102+ if ( this . history [ this . history . length - 1 ] === snippetId ) return
103+
104+ if ( this . history . length === HISTORY_LIMIT ) this . history . shift ( )
105+
106+ this . history . push ( snippetId )
107+ this . historyIndex = this . history . length - 1
108+ } ,
109+ historyBack ( ) {
110+ if ( this . historyIndex === 0 ) return
111+
112+ this . historyIndex = this . historyIndex - 1
113+ goToSnippet ( this . history [ this . historyIndex ] )
114+ } ,
115+ historyForward ( ) {
116+ if ( this . historyIndex === this . history . length - 1 ) return
117+
118+ this . historyIndex = this . historyIndex + 1
119+ goToSnippet ( this . history [ this . historyIndex ] )
94120 }
95121 }
96122} )
0 commit comments