Add status bar icon to toggle linter

Signed-off-by: Yukai Huang <yukaihuangtw@gmail.com>
This commit is contained in:
Yukai Huang 2019-08-17 00:17:22 +08:00
parent 968e042b05
commit ad5be66206
No known key found for this signature in database
GPG Key ID: D4D3B2F0E99D4914
3 changed files with 46 additions and 2 deletions

View File

@ -513,6 +513,7 @@ div[contenteditable]:empty:not(:focus):before{
.status-bar .status-indicators .status-keymap > a, .status-bar .status-indicators .status-keymap > a,
.status-bar .status-indicators .status-theme > a, .status-bar .status-indicators .status-theme > a,
.status-bar .status-indicators .status-spellcheck > a, .status-bar .status-indicators .status-spellcheck > a,
.status-bar .status-indicators .status-linter > a,
.status-bar .status-indicators .status-preferences > a { .status-bar .status-indicators .status-preferences > a {
color: inherit; color: inherit;
text-decoration: none; text-decoration: none;
@ -520,6 +521,7 @@ div[contenteditable]:empty:not(:focus):before{
.status-bar .status-indicators .status-theme, .status-bar .status-indicators .status-theme,
.status-bar .status-indicators .status-spellcheck, .status-bar .status-indicators .status-spellcheck,
.status-bar .status-indicators .status-linter,
.status-bar .status-indicators .status-preferences { .status-bar .status-indicators .status-preferences {
padding: 0 4.3px; padding: 0 4.3px;
} }
@ -540,17 +542,20 @@ div[contenteditable]:empty:not(:focus):before{
} }
.ui-theme-toggle, .ui-theme-toggle,
.ui-linter-toggle,
.ui-spellcheck-toggle { .ui-spellcheck-toggle {
opacity: 0.2; opacity: 0.2;
cursor: pointer; cursor: pointer;
} }
.ui-theme-toggle.active, .ui-theme-toggle.active,
.ui-linter-toggle.active,
.ui-spellcheck-toggle.active { .ui-spellcheck-toggle.active {
opacity: 1; opacity: 1;
} }
.ui-theme-toggle:hover, .ui-theme-toggle:hover,
.ui-linter-toggle:hover,
.ui-spellcheck-toggle:hover { .ui-spellcheck-toggle:hover {
opacity: 0.8; opacity: 0.8;
} }

View File

@ -232,6 +232,7 @@ export default class Editor {
this.statusLength = this.statusBar.find('.status-length') this.statusLength = this.statusBar.find('.status-length')
this.statusTheme = this.statusBar.find('.status-theme') this.statusTheme = this.statusBar.find('.status-theme')
this.statusSpellcheck = this.statusBar.find('.status-spellcheck') this.statusSpellcheck = this.statusBar.find('.status-spellcheck')
this.statusLinter = this.statusBar.find('.status-linter')
this.statusPreferences = this.statusBar.find('.status-preferences') this.statusPreferences = this.statusBar.find('.status-preferences')
this.statusPanel = this.editor.addPanel(this.statusBar[0], { this.statusPanel = this.editor.addPanel(this.statusBar[0], {
position: 'bottom' position: 'bottom'
@ -241,6 +242,7 @@ export default class Editor {
this.setKeymap() this.setKeymap()
this.setTheme() this.setTheme()
this.setSpellcheck() this.setSpellcheck()
this.setLinter()
this.setPreferences() this.setPreferences()
} }
@ -499,6 +501,42 @@ export default class Editor {
} }
} }
toggleLinter (enable) {
const gutters = this.editor.getOption('gutters')
const lintGutter = 'CodeMirror-lint-markers'
if (enable) {
if (!gutters.includes(lintGutter)) {
this.editor.setOption('gutters', [lintGutter, ...gutters])
}
Cookies.set('linter', true, {
expires: 365
})
} else {
this.editor.setOption('gutters', gutters.filter(g => g !== lintGutter))
Cookies.remove('linter')
}
this.editor.setOption('lint', enable)
}
setLinter () {
const linterToggle = this.statusLinter.find('.ui-linter-toggle')
const updateLinterStatus = (enable) => {
linterToggle.toggleClass('active', enable)
}
linterToggle.click(() => {
const lintEnable = this.editor.getOption('lint')
this.toggleLinter.bind(this)(!lintEnable)
updateLinterStatus(!lintEnable)
})
const enable = !!Cookies.get('linter')
this.toggleLinter.bind(this)(enable)
updateLinterStatus(enable)
}
resetEditorKeymapToBrowserKeymap () { resetEditorKeymapToBrowserKeymap () {
var keymap = this.editor.getOption('keyMap') var keymap = this.editor.getOption('keyMap')
if (!this.jumpToAddressBarKeymapValue) { if (!this.jumpToAddressBarKeymapValue) {
@ -553,7 +591,6 @@ export default class Editor {
this.editor = CodeMirror.fromTextArea(textit, { this.editor = CodeMirror.fromTextArea(textit, {
mode: defaultEditorMode, mode: defaultEditorMode,
backdrop: defaultEditorMode, backdrop: defaultEditorMode,
lint: true,
keyMap: 'sublime', keyMap: 'sublime',
viewportMargin: viewportMargin, viewportMargin: viewportMargin,
styleActiveLine: true, styleActiveLine: true,
@ -573,7 +610,6 @@ export default class Editor {
autoCloseTags: true, autoCloseTags: true,
foldGutter: true, foldGutter: true,
gutters: [ gutters: [
'CodeMirror-lint-markers',
'CodeMirror-linenumbers', 'CodeMirror-linenumbers',
'authorship-gutters', 'authorship-gutters',
'CodeMirror-foldgutter' 'CodeMirror-foldgutter'

View File

@ -37,5 +37,8 @@
<div class="status-spellcheck"> <div class="status-spellcheck">
<a class="ui-spellcheck-toggle" title="Toggle spellcheck"><i class="fa fa-check fa-fw"></i></a> <a class="ui-spellcheck-toggle" title="Toggle spellcheck"><i class="fa fa-check fa-fw"></i></a>
</div> </div>
<div class="status-linter">
<a class="ui-linter-toggle" title="Toggle linter"><i class="fa fa-lightbulb-o fa-fw"></i></a>
</div>
</div> </div>
</div> </div>