From 6fa6718a8840ca1c4d61b2d547bea5cc05a92d07 Mon Sep 17 00:00:00 2001 From: Jonathan Clem Date: Tue, 10 Mar 2020 12:42:42 -0400 Subject: [PATCH 1/3] Use `replace` instead of `push` on code change Using `push` pollutes the browser history, adding a new entry on every keystroke in the editor. This commit replaces it with `replace`, ensuring that the editor gets a single history entry, but that the URL is still updated as code changes. --- src/components/Editor.svelte | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/Editor.svelte b/src/components/Editor.svelte index 405a655d..d1b02957 100644 --- a/src/components/Editor.svelte +++ b/src/components/Editor.svelte @@ -36,7 +36,7 @@ const handleCodeUpdate = code => { codeErrorStore.set(e); console.log('Error in parsed', e.hash); const str = JSON.stringify({ code: code, mermaid: conf }); - push('/edit/' + Base64.encodeURI(str)) + replace('/edit/' + Base64.encodeURI(str)) const l = e.hash.line; decArr.push(edit.deltaDecorations([], [ { range: new monaco.Range(e.hash.loc.first_line,e.hash.loc.last_line,e.hash.loc.first_column,e.hash.loc.last_column), options: { inlineClassName: 'myInlineDecoration' }}] From 824111df126595231aad33ca82bcf60c9741069b Mon Sep 17 00:00:00 2001 From: Jonathan Clem Date: Tue, 10 Mar 2020 12:48:39 -0400 Subject: [PATCH 2/3] Replace URL on config update, rather than push an entry --- src/components/Config.svelte | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/Config.svelte b/src/components/Config.svelte index dc36da2f..f403f52b 100644 --- a/src/components/Config.svelte +++ b/src/components/Config.svelte @@ -38,7 +38,7 @@ const handleConfUpdate = conf => { console.log('Error in parsed', e); configErrorStore.set(e); const str = JSON.stringify({ code, mermaid: oldConf }); - push('/edit/' + Base64.encodeURI(str)) + replace('/edit/' + Base64.encodeURI(str)) } }; From 65d676059d7450d57981495a357164a8cdbb38f2 Mon Sep 17 00:00:00 2001 From: Jonathan Clem Date: Tue, 10 Mar 2020 12:53:15 -0400 Subject: [PATCH 3/3] Replace URL instead of pushing an entry in `updateCodeStore` --- src/code-store.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/code-store.js b/src/code-store.js index 5467901d..50d99deb 100644 --- a/src/code-store.js +++ b/src/code-store.js @@ -35,5 +35,5 @@ export const fromUrl = data => { }; export const updateCodeStore = newState => { codeStore.set(newState); - push('/edit/' + Base64.encodeURI(JSON.stringify(newState))) + replace('/edit/' + Base64.encodeURI(JSON.stringify(newState))) };