Skip to content

Commit 4d95adb

Browse files
committed
add localstorage buffer
1 parent ef66d0f commit 4d95adb

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/pages/Home.vue

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,17 @@ import marked from "../lib/marked";
6969
7070
const toastRef = ref(null);
7171
72-
const state = reactive({ code: defaultMarkdownText, showPreview: false });
72+
const STORAGE_TOKEN = Symbol("reaper-mark").toString();
73+
74+
const getDefaultCode = () => {
75+
const existingCode = localStorage.getItem(STORAGE_TOKEN);
76+
if (existingCode && existingCode.length) {
77+
return existingCode;
78+
}
79+
return defaultMarkdownText;
80+
};
81+
82+
const state = reactive({ code: getDefaultCode(), showPreview: false });
7383
7484
onMounted(() => {
7585
document.addEventListener("keydown", shortcutListener.bind(this));
@@ -98,6 +108,7 @@ function shortcutListener(e) {
98108
99109
function handleChange(code) {
100110
state.code = code;
111+
localStorage.setItem(STORAGE_TOKEN, code);
101112
}
102113
103114
async function handleCopyAsHTML() {

0 commit comments

Comments
 (0)