Skip to content
This repository has been archived by the owner on May 26, 2020. It is now read-only.

Commit

Permalink
fix(editor): editor initialization fixed
Browse files Browse the repository at this point in the history
related to #351
related to  #352

Signed-off-by: ggalkin gleb.galkin@zalando.de
Signed-off-by: ggalkin <gleb.galkin@zalando.de>
  • Loading branch information
ggalkin committed Jul 16, 2019
1 parent 43bd86b commit b67c15a
Show file tree
Hide file tree
Showing 5 changed files with 100 additions and 109 deletions.
19 changes: 1 addition & 18 deletions src/pages/options.html
Original file line number Diff line number Diff line change
Expand Up @@ -98,23 +98,6 @@ <h1>Options</h1>
</span> autoscroll editor into view
</label>
</div>
<!--<div class="checkbox">
<label>
<input id="useSoftTabs" type="checkbox">
<span class="checkbox-material">
<span class="check"></span>
</span> useSoftTabs
</label>
</div>
<div class="checkbox">
<label>
<input id="navigateWithinSoftTabs" type="checkbox">
<span class="checkbox-material">
<span class="check"></span>
</span> navigateWithinSoftTabs
</label>
</div>-->
<!-- renderer -->
<div class="checkbox">
<label>
<input id="showLineNumbers" type="checkbox">
Expand Down Expand Up @@ -189,4 +172,4 @@ <h1>Options</h1>
<script type="text/javascript" src="../js/options.js"></script>
</body>

</html>
</html>
63 changes: 63 additions & 0 deletions src/ts/editorConfig.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
export const aceThemePath = 'ace/theme/';

export const themes = {
Default: aceThemePath + 'github',
Monokai: aceThemePath + 'monokai',
Ambiance: aceThemePath + 'ambiance',
Chaos: aceThemePath + 'chaos',
Chrome: aceThemePath + 'chrome',
Clouds: aceThemePath + 'clouds',
Clouds_midnight: aceThemePath + 'clouds_midnight',
Cobalt: aceThemePath + 'cobalt',
Crimson_editor: aceThemePath + 'crimson_editor',
Dawn: aceThemePath + 'dawn',
Dracula: aceThemePath + 'dracula',
Dreamweaver: aceThemePath + 'dreamweaver',
Eclipse: aceThemePath + 'eclipse',
Github: aceThemePath + 'github',
Gob: aceThemePath + 'gob',
Gruvbox: aceThemePath + 'gruvbox',
Idle_fingers: aceThemePath + 'idle_fingers',
Iplastic: aceThemePath + 'iplastic',
Katzenmilch: aceThemePath + 'katzenmilch',
Kr_theme: aceThemePath + 'kr_theme',
Kuroir: aceThemePath + 'kuroir',
Merbivore: aceThemePath + 'merbivore',
Merbivore_soft: aceThemePath + 'merbivore_soft',
Mono_industrial: aceThemePath + 'mono_industrial',
Pastel_on_dark: aceThemePath + 'pastel_on_dark',
Solarized_dark: aceThemePath + 'solarized_dark',
Solarized_light: aceThemePath + 'solarized_light',
Sqlserver: aceThemePath + 'sqlserver',
Terminal: aceThemePath + 'terminal',
Textmate: aceThemePath + 'textmate',
Tomorrow: aceThemePath + 'tomorrow',
Tomorrow_night: aceThemePath + 'tomorrow_night',
Tomorrow_night_blue: aceThemePath + 'tomorrow_night_blue',
Tomorrow_night_bright: aceThemePath + 'tomorrow_night_bright',
Tomorrow_night_eighties: aceThemePath + 'tomorrow_night_eighties',
Twilight: aceThemePath + 'twilight',
Vibrant_ink: aceThemePath + 'vibrant_ink',
Xcode: aceThemePath + 'xcode'
};

export const defaultCustomOptions = {
liveUrlQuery: true,
hideUnfilteredJsonByDefault: false
};

export const defaultEditorOptions = {
highlightActiveLine: true,
highlightSelectedWord: true,
readOnly: true,
autoScrollEditorIntoView: false,
showLineNumbers: true,
showGutter: true,
displayIndentGuides: true,
fixedWidthGutter: false,
theme: themes.Default,
fontSize: '14px',
fontFamily:
'Monaco, Menlo, "Ubuntu Mono", Consolas, source-code-pro, monospace',
dragEnabled: true
};
8 changes: 6 additions & 2 deletions src/ts/index.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import { h, render } from 'preact';
import checkIfJson from './util/check-if-json';
import App from './App';
import { h, render } from "preact";
import { checkStorageOptions } from './storage';
import {
defaultEditorOptions,
} from './editorConfig';

function onLoad() {
checkIfJson((pre) => {
pre.hidden = true;

checkStorageOptions(defaultEditorOptions);
loadExtension(pre);
});
}
Expand Down
81 changes: 7 additions & 74 deletions src/ts/options.ts
Original file line number Diff line number Diff line change
@@ -1,83 +1,16 @@
import { saveStorage } from './storage';

const aceThemePath = 'ace/theme/';

const themes = {
Default: aceThemePath + 'github',
Monokai: aceThemePath + 'monokai',
Ambiance: aceThemePath + 'ambiance',
Chaos: aceThemePath + 'chaos',
Chrome: aceThemePath + 'chrome',
Clouds: aceThemePath + 'clouds',
Clouds_midnight: aceThemePath + 'clouds_midnight',
Cobalt: aceThemePath + 'cobalt',
Crimson_editor: aceThemePath + 'crimson_editor',
Dawn: aceThemePath + 'dawn',
Dracula: aceThemePath + 'dracula',
Dreamweaver: aceThemePath + 'dreamweaver',
Eclipse: aceThemePath + 'eclipse',
Github: aceThemePath + 'github',
Gob: aceThemePath + 'gob',
Gruvbox: aceThemePath + 'gruvbox',
Idle_fingers: aceThemePath + 'idle_fingers',
Iplastic: aceThemePath + 'iplastic',
Katzenmilch: aceThemePath + 'katzenmilch',
Kr_theme: aceThemePath + 'kr_theme',
Kuroir: aceThemePath + 'kuroir',
Merbivore: aceThemePath + 'merbivore',
Merbivore_soft: aceThemePath + 'merbivore_soft',
Mono_industrial: aceThemePath + 'mono_industrial',
Pastel_on_dark: aceThemePath + 'pastel_on_dark',
Solarized_dark: aceThemePath + 'solarized_dark',
Solarized_light: aceThemePath + 'solarized_light',
Sqlserver: aceThemePath + 'sqlserver',
Terminal: aceThemePath + 'terminal',
Textmate: aceThemePath + 'textmate',
Tomorrow: aceThemePath + 'tomorrow',
Tomorrow_night: aceThemePath + 'tomorrow_night',
Tomorrow_night_blue: aceThemePath + 'tomorrow_night_blue',
Tomorrow_night_bright: aceThemePath + 'tomorrow_night_bright',
Tomorrow_night_eighties: aceThemePath + 'tomorrow_night_eighties',
Twilight: aceThemePath + 'twilight',
Vibrant_ink: aceThemePath + 'vibrant_ink',
Xcode: aceThemePath + 'xcode'
};

const defaultEditorOptions = {
highlightActiveLine: true,
highlightSelectedWord: true,
readOnly: true,
autoScrollEditorIntoView: false,
showLineNumbers: true,
showGutter: true,
displayIndentGuides: true,
fixedWidthGutter: false,
theme: themes.Default,
fontSize: '14px',
fontFamily:
'Monaco, Menlo, "Ubuntu Mono", Consolas, source-code-pro, monospace',
dragEnabled: true
};

const defaultCustomOptions = {
liveUrlQuery: true,
hideUnfilteredJsonByDefault: false
};
import { saveStorage, checkStorageOptions } from './storage';
import {
defaultEditorOptions,
defaultCustomOptions,
themes
} from './editorConfig';

export const defaultOptions = Object.assign(
{},
defaultEditorOptions,
defaultCustomOptions
);

export function checkStorageOptions() {
chrome.storage.sync.get(['options'], result => {
if (result.options === undefined) {
saveStorage(JSON.stringify(defaultOptions));
}
});
}

export function parseOptions(options: string) {
return Object.assign({}, defaultOptions, JSON.parse(options));
}
Expand Down Expand Up @@ -180,5 +113,5 @@ function saveOptions() {
});
}

checkStorageOptions();
checkStorageOptions(defaultEditorOptions);
getOptions();
38 changes: 23 additions & 15 deletions src/ts/storage.ts
Original file line number Diff line number Diff line change
@@ -1,48 +1,56 @@
const domain = new URL(location.href).hostname;

type SavedFilter = {
domain: string,
filter: string,
domain: string;
filter: string;
};

export function checkStorageOptions(defaultOptions) {
chrome.storage.sync.get(['options'], result => {
if (result.options === undefined) {
saveStorage(JSON.stringify(defaultOptions));
}
});
}

export function saveStorage(value) {
chrome.storage.sync.set({ options: value }, function () {
});
chrome.storage.sync.set({ options: value }, function() {});
}

export function addFilter(filter: string, done?: () => void) {
chrome.storage.sync.get(['storedFilters'], (result) => {
const storedFilters = result.storedFilters as string[] || [];
chrome.storage.sync.get(['storedFilters'], result => {
const storedFilters = (result.storedFilters as string[]) || [];
const filterObj = {
filter,
domain
}
};
let filterSet = new Set(storedFilters);
filterSet.add(JSON.stringify(filterObj));
chrome.storage.sync.set({ storedFilters: Array.from(filterSet) }, done)
chrome.storage.sync.set({ storedFilters: Array.from(filterSet) }, done);
});
}

export function removeFilter(filter: string, done?: () => void) {
chrome.storage.sync.get(['storedFilters'], (result) => {
const storedFilters = result.storedFilters as string[] || [];
chrome.storage.sync.get(['storedFilters'], result => {
const storedFilters = (result.storedFilters as string[]) || [];
let filterSet = new Set(storedFilters);
const filterObj = {
filter,
domain
}
};
filterSet.delete(JSON.stringify(filterObj));
chrome.storage.sync.set({ storedFilters: Array.from(filterSet) }, done);
});
}

export function getFilters(callback: (filterlist: string[]) => void) {
chrome.storage.sync.get(['storedFilters'], (result) => {
const filtersForDomain = (result.storedFilters as string[] || [])
.map(s => JSON.parse(s) as SavedFilter)
chrome.storage.sync.get(['storedFilters'], result => {
const filtersForDomain = ((result.storedFilters as string[]) || []).map(
s => JSON.parse(s) as SavedFilter
);
// .filter(f => f.domain === domain)
// In the future this will make filters linked to the domain they were created in.
const filterStrings = filtersForDomain.map(({ filter }) => filter)
const filterStrings = filtersForDomain.map(({ filter }) => filter);
callback(filterStrings);
});
}

0 comments on commit b67c15a

Please sign in to comment.