aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--src/editor.mjs16
1 files changed, 10 insertions, 6 deletions
diff --git a/src/editor.mjs b/src/editor.mjs
index 866237a..f0b4af0 100644
--- a/src/editor.mjs
+++ b/src/editor.mjs
@@ -7,6 +7,7 @@ import { shiftByWindow } from './utils.mjs'
7 7
8// Set up Containers {{{ 8// Set up Containers {{{
9 9
10const url = new URL(window.location)
10const context = document.querySelector('[data-mode]') 11const context = document.querySelector('[data-mode]')
11const dumbyContainer = document.querySelector('.DumbyMap') 12const dumbyContainer = document.querySelector('.DumbyMap')
12const textArea = document.querySelector('.editor textarea') 13const textArea = document.querySelector('.editor textarea')
@@ -134,6 +135,7 @@ const editor = new EasyMDE({
134 action: () => { 135 action: () => {
135 const state = { content: editor.value() } 136 const state = { content: editor.value() }
136 window.location.hash = encodeURIComponent(JSON.stringify(state)) 137 window.location.hash = encodeURIComponent(JSON.stringify(state))
138 window.location.search = ''
137 navigator.clipboard.writeText(window.location.href) 139 navigator.clipboard.writeText(window.location.href)
138 window.alert('URL updated in address bar, you can save current page as bookmark') 140 window.alert('URL updated in address bar, you can save current page as bookmark')
139 } 141 }
@@ -239,17 +241,19 @@ const getContentFromHash = hash => {
239 const state = getStateFromHash(hash) 241 const state = getStateFromHash(hash)
240 return state.content 242 return state.content
241} 243}
244const contentFromHash = getContentFromHash(window.location.hash)
242 245
243const initialState = getStateFromHash(window.location.hash) 246if (url.searchParams.get('content') === 'tutorial') {
244window.location.hash = '' 247 console.log('tutorial')
245const contentFromHash = initialState.content 248 editor.value(defaultContent)
246 249} else if (contentFromHash) {
247// Seems like autosave would overwrite initialValue, set content from hash here 250 // Seems like autosave would overwrite initialValue, set content from hash here
248if (contentFromHash) {
249 editor.cleanup() 251 editor.cleanup()
250 editor.value(contentFromHash) 252 editor.value(contentFromHash)
251} 253}
252 254
255window.location.hash = ''
256
253// }}} 257// }}}
254// Set up logic about editor content {{{ 258// Set up logic about editor content {{{
255 259