-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Add preference to disable table editor shortcuts and migrate preferences to localStorage #1901
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,3 +1,4 @@ | ||||||||||||||||
| /* eslint-env browser */ | ||||||||||||||||
| /* global CodeMirror, $, editor, Cookies */ | ||||||||||||||||
| import { options, Alignment, FormatType } from '@susisu/mte-kernel' | ||||||||||||||||
| import debounce from 'lodash/debounce' | ||||||||||||||||
|
|
@@ -11,6 +12,39 @@ import CodeMirrorSpellChecker, { supportLanguages, supportLanguageCodes } from ' | |||||||||||||||
| import { initTableEditor } from './table-editor' | ||||||||||||||||
| import { availableThemes } from './constants' | ||||||||||||||||
|
|
||||||||||||||||
| // Storage utility class for localStorage operations | ||||||||||||||||
| class Storage { | ||||||||||||||||
| static get (key, defaultValue = null) { | ||||||||||||||||
| try { | ||||||||||||||||
| const value = localStorage.getItem(key) | ||||||||||||||||
| return value !== null ? value : defaultValue | ||||||||||||||||
| } catch (e) { | ||||||||||||||||
| console.error('Error getting from localStorage:', e) | ||||||||||||||||
| return defaultValue | ||||||||||||||||
| } | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| static set (key, value, options = {}) { | ||||||||||||||||
| try { | ||||||||||||||||
| localStorage.setItem(key, value) | ||||||||||||||||
| return true | ||||||||||||||||
| } catch (e) { | ||||||||||||||||
| console.error('Error setting to localStorage:', e) | ||||||||||||||||
| return false | ||||||||||||||||
| } | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| static remove (key) { | ||||||||||||||||
| try { | ||||||||||||||||
| localStorage.removeItem(key) | ||||||||||||||||
| return true | ||||||||||||||||
| } catch (e) { | ||||||||||||||||
| console.error('Error removing from localStorage:', e) | ||||||||||||||||
| return false | ||||||||||||||||
| } | ||||||||||||||||
| } | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| /* config section */ | ||||||||||||||||
| const isMac = CodeMirror.keyMap.default === CodeMirror.keyMap.macDefault | ||||||||||||||||
| const defaultEditorMode = 'gfm' | ||||||||||||||||
|
|
@@ -183,6 +217,39 @@ export default class Editor { | |||||||||||||||
| CodeMirror.defineMode('markmap', function (config, modeConfig) { | ||||||||||||||||
| return CodeMirror.overlayMode(CodeMirror.getMode(config, 'gfm'), ignoreOverlay) | ||||||||||||||||
| }) | ||||||||||||||||
|
|
||||||||||||||||
| // Migrate preferences from cookies to localStorage | ||||||||||||||||
| this.migratePreferences() | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| // Migrate preferences from cookies to localStorage | ||||||||||||||||
| migratePreferences () { | ||||||||||||||||
| // Only run migration if window and localStorage are available | ||||||||||||||||
| if (typeof window === 'undefined' || typeof localStorage === 'undefined' || typeof Cookies === 'undefined') { | ||||||||||||||||
| return | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| const preferencesToMigrate = [ | ||||||||||||||||
| 'indent_type', | ||||||||||||||||
| 'tab_size', | ||||||||||||||||
| 'space_units', | ||||||||||||||||
| 'keymap', | ||||||||||||||||
| 'theme', | ||||||||||||||||
| 'spellcheck', | ||||||||||||||||
| 'linter', | ||||||||||||||||
| 'preferences-override-browser-keymap', | ||||||||||||||||
| 'preferences-disable-table-shortcuts' | ||||||||||||||||
| ] | ||||||||||||||||
|
|
||||||||||||||||
| preferencesToMigrate.forEach(key => { | ||||||||||||||||
| // Check if preference exists in cookies but not in localStorage | ||||||||||||||||
| const cookieValue = Cookies.get(key) | ||||||||||||||||
| if (cookieValue !== undefined && Storage.get(key) === null) { | ||||||||||||||||
| // Migrate the preference to localStorage | ||||||||||||||||
| Storage.set(key, cookieValue) | ||||||||||||||||
| console.log(`Migrated preference ${key} from cookies to localStorage`) | ||||||||||||||||
|
Comment on lines
+249
to
+250
|
||||||||||||||||
| Storage.set(key, cookieValue) | |
| console.log(`Migrated preference ${key} from cookies to localStorage`) | |
| if (Storage.set(key, cookieValue)) { | |
| // Remove the cookie after successful migration | |
| Cookies.remove(key) | |
| console.log(`Migrated and removed cookie for preference ${key} from cookies to localStorage`) | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.