2018-11-07 06:09:29 +00:00
|
|
|
/* global dirtyReporter
|
|
|
|
createAppliesToLineWidget messageBox
|
|
|
|
sectionsToMozFormat
|
|
|
|
createMetaCompiler linter createLivePreview cmFactory $ $create API prefs t
|
|
|
|
chromeSync */
|
|
|
|
/* exported createSourceEditor */
|
2017-09-11 16:09:25 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
function createSourceEditor(style) {
|
|
|
|
$('#name').disabled = true;
|
2017-12-24 23:26:01 +00:00
|
|
|
$('#save-button').disabled = true;
|
2017-11-26 13:04:03 +00:00
|
|
|
$('#mozilla-format-container').remove();
|
2018-01-05 10:20:46 +00:00
|
|
|
$('#save-button').onclick = save;
|
2018-08-24 11:31:29 +00:00
|
|
|
$('#header').addEventListener('wheel', headerOnScroll);
|
2017-11-26 13:04:03 +00:00
|
|
|
$('#sections').textContent = '';
|
2017-12-03 21:12:09 +00:00
|
|
|
$('#sections').appendChild($create('.single-editor'));
|
2017-09-11 16:09:25 +00:00
|
|
|
|
|
|
|
const dirty = dirtyReporter();
|
|
|
|
dirty.onChange(() => {
|
2018-08-02 17:54:40 +00:00
|
|
|
const isDirty = dirty.isDirty();
|
|
|
|
document.body.classList.toggle('dirty', isDirty);
|
|
|
|
$('#save-button').disabled = !isDirty;
|
2017-09-13 09:33:32 +00:00
|
|
|
updateTitle();
|
2017-09-11 16:09:25 +00:00
|
|
|
});
|
|
|
|
|
2017-10-08 15:26:55 +00:00
|
|
|
// normalize style
|
2018-01-05 10:26:11 +00:00
|
|
|
if (!style.id) setupNewStyle(style);
|
2017-10-08 15:26:55 +00:00
|
|
|
|
2018-11-07 06:09:29 +00:00
|
|
|
const cm = cmFactory.create($('.single-editor'), {
|
2018-01-05 10:20:46 +00:00
|
|
|
value: style.sourceCode,
|
|
|
|
});
|
|
|
|
let savedGeneration = cm.changeGeneration();
|
|
|
|
|
2018-11-07 06:09:29 +00:00
|
|
|
const livePreview = createLivePreview(preprocess);
|
|
|
|
livePreview.show(Boolean(style.id));
|
2018-01-05 10:20:46 +00:00
|
|
|
|
|
|
|
$('#enabled').onchange = function () {
|
|
|
|
const value = this.checked;
|
|
|
|
dirty.modify('enabled', style.enabled, value);
|
|
|
|
style.enabled = value;
|
2018-11-07 06:09:29 +00:00
|
|
|
updateLivePreview();
|
2018-01-05 10:20:46 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
cm.on('changes', () => {
|
|
|
|
dirty.modify('sourceGeneration', savedGeneration, cm.changeGeneration());
|
2018-11-07 06:09:29 +00:00
|
|
|
updateLivePreview();
|
2018-01-05 10:20:46 +00:00
|
|
|
});
|
|
|
|
|
2017-12-21 13:04:12 +00:00
|
|
|
cm.operation(initAppliesToLineWidget);
|
2018-01-05 10:20:46 +00:00
|
|
|
|
2018-10-01 14:03:17 +00:00
|
|
|
const metaCompiler = createMetaCompiler(cm);
|
|
|
|
metaCompiler.onUpdated(meta => {
|
|
|
|
style.usercssData = meta;
|
|
|
|
style.name = meta.name;
|
|
|
|
style.url = meta.homepageURL;
|
|
|
|
updateMeta();
|
|
|
|
});
|
2018-01-05 10:20:46 +00:00
|
|
|
|
2018-10-01 14:03:17 +00:00
|
|
|
linter.enableForEditor(cm);
|
|
|
|
|
|
|
|
updateMeta().then(() => {
|
2018-01-05 10:20:46 +00:00
|
|
|
|
|
|
|
let prevMode = NaN;
|
|
|
|
cm.on('optionChange', (cm, option) => {
|
|
|
|
if (option !== 'mode') return;
|
|
|
|
const mode = getModeName();
|
|
|
|
if (mode === prevMode) return;
|
|
|
|
prevMode = mode;
|
2018-10-01 14:03:17 +00:00
|
|
|
linter.run();
|
2018-01-05 10:20:46 +00:00
|
|
|
updateLinterSwitch();
|
|
|
|
});
|
|
|
|
|
|
|
|
$('#editor.linter').addEventListener('change', updateLinterSwitch);
|
|
|
|
updateLinterSwitch();
|
|
|
|
|
2017-12-11 05:32:11 +00:00
|
|
|
setTimeout(() => {
|
|
|
|
if ((document.activeElement || {}).localName !== 'input') {
|
|
|
|
cm.focus();
|
|
|
|
}
|
|
|
|
});
|
2017-11-22 00:38:29 +00:00
|
|
|
});
|
2017-09-13 08:58:03 +00:00
|
|
|
|
2018-11-07 06:09:29 +00:00
|
|
|
function preprocess(style) {
|
|
|
|
return API.buildUsercss({
|
2018-11-25 13:27:11 +00:00
|
|
|
styleId: style.id,
|
2018-11-07 06:09:29 +00:00
|
|
|
sourceCode: style.sourceCode,
|
|
|
|
assignVars: true
|
|
|
|
})
|
|
|
|
.then(({style: newStyle}) => {
|
|
|
|
delete newStyle.enabled;
|
|
|
|
return Object.assign(style, newStyle);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function updateLivePreview() {
|
|
|
|
if (!style.id) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
livePreview.update(Object.assign({}, style, {sourceCode: cm.getValue()}));
|
|
|
|
}
|
|
|
|
|
2017-11-01 01:11:27 +00:00
|
|
|
function initAppliesToLineWidget() {
|
|
|
|
const PREF_NAME = 'editor.appliesToLineWidget';
|
|
|
|
const widget = createAppliesToLineWidget(cm);
|
|
|
|
widget.toggle(prefs.get(PREF_NAME));
|
2017-11-26 13:04:03 +00:00
|
|
|
prefs.subscribe([PREF_NAME], (key, value) => widget.toggle(value));
|
2017-11-01 01:11:27 +00:00
|
|
|
}
|
|
|
|
|
2018-01-05 10:20:46 +00:00
|
|
|
function updateLinterSwitch() {
|
|
|
|
const el = $('#editor.linter');
|
2018-10-01 14:03:17 +00:00
|
|
|
el.value = getCurrentLinter();
|
2018-01-05 10:20:46 +00:00
|
|
|
const cssLintOption = $('[value="csslint"]', el);
|
|
|
|
const mode = getModeName();
|
|
|
|
if (mode !== 'css') {
|
|
|
|
cssLintOption.disabled = true;
|
|
|
|
cssLintOption.title = t('linterCSSLintIncompatible', mode);
|
|
|
|
} else {
|
|
|
|
cssLintOption.disabled = false;
|
|
|
|
cssLintOption.title = '';
|
2017-10-07 10:00:25 +00:00
|
|
|
}
|
2017-10-15 19:58:02 +00:00
|
|
|
}
|
2017-10-07 10:00:25 +00:00
|
|
|
|
2018-10-01 14:03:17 +00:00
|
|
|
function getCurrentLinter() {
|
|
|
|
const name = prefs.get('editor.linter');
|
|
|
|
if (cm.getOption('mode') !== 'css' && name === 'csslint') {
|
|
|
|
return 'stylelint';
|
|
|
|
}
|
|
|
|
return name;
|
|
|
|
}
|
|
|
|
|
2017-10-08 15:26:55 +00:00
|
|
|
function setupNewStyle(style) {
|
2018-02-22 09:41:55 +00:00
|
|
|
style.sections[0].code = ' '.repeat(prefs.get('editor.tabSize')) +
|
|
|
|
`/* ${t('usercssReplaceTemplateSectionBody')} */`;
|
2017-12-26 20:39:52 +00:00
|
|
|
let section = sectionsToMozFormat(style);
|
2017-10-08 15:26:55 +00:00
|
|
|
if (!section.includes('@-moz-document')) {
|
|
|
|
style.sections[0].domains = ['example.com'];
|
2017-12-26 20:39:52 +00:00
|
|
|
section = sectionsToMozFormat(style);
|
2017-10-08 15:26:55 +00:00
|
|
|
}
|
2017-11-26 13:04:03 +00:00
|
|
|
const DEFAULT_CODE = `
|
|
|
|
/* ==UserStyle==
|
2018-08-06 10:35:33 +00:00
|
|
|
@name ${''/* a trick to preserve the trailing spaces */}
|
2017-11-26 13:04:03 +00:00
|
|
|
@namespace github.com/openstyles/stylus
|
2018-08-06 10:35:33 +00:00
|
|
|
@version 1.0.0
|
2017-11-26 13:04:03 +00:00
|
|
|
@description A new userstyle
|
|
|
|
@author Me
|
|
|
|
==/UserStyle== */
|
2018-02-22 09:41:55 +00:00
|
|
|
`.replace(/^\s+/gm, '');
|
2018-01-05 10:20:46 +00:00
|
|
|
|
2017-11-26 21:45:21 +00:00
|
|
|
dirty.clear('sourceGeneration');
|
2017-11-26 13:04:03 +00:00
|
|
|
style.sourceCode = '';
|
2018-01-05 10:20:46 +00:00
|
|
|
|
2018-01-01 17:02:49 +00:00
|
|
|
chromeSync.getLZValue('usercssTemplate').then(code => {
|
2018-08-18 20:17:20 +00:00
|
|
|
const name = style.name || t('usercssReplaceTemplateName');
|
|
|
|
const date = new Date().toLocaleString();
|
2018-02-22 09:41:55 +00:00
|
|
|
code = code || DEFAULT_CODE;
|
2018-08-06 10:35:33 +00:00
|
|
|
code = code.replace(/@name(\s*)(?=[\r\n])/, (str, space) =>
|
2018-08-18 20:17:20 +00:00
|
|
|
`${str}${space ? '' : ' '}${name} - ${date}`);
|
2018-02-22 09:59:56 +00:00
|
|
|
// strip the last dummy section if any, add an empty line followed by the section
|
2018-08-06 17:56:33 +00:00
|
|
|
style.sourceCode = code.replace(/\s*@-moz-document[^{]*\{[^}]*\}\s*$|\s+$/g, '') + '\n\n' + section;
|
2017-11-26 13:04:03 +00:00
|
|
|
cm.startOperation();
|
|
|
|
cm.setValue(style.sourceCode);
|
|
|
|
cm.clearHistory();
|
|
|
|
cm.markClean();
|
|
|
|
cm.endOperation();
|
2017-11-26 21:45:21 +00:00
|
|
|
dirty.clear('sourceGeneration');
|
|
|
|
savedGeneration = cm.changeGeneration();
|
2017-11-26 13:04:03 +00:00
|
|
|
});
|
2017-10-08 15:26:55 +00:00
|
|
|
}
|
|
|
|
|
2017-11-08 23:26:51 +00:00
|
|
|
function updateMeta() {
|
2017-09-11 16:09:25 +00:00
|
|
|
$('#name').value = style.name;
|
|
|
|
$('#enabled').checked = style.enabled;
|
|
|
|
$('#url').href = style.url;
|
2017-09-13 09:33:32 +00:00
|
|
|
updateTitle();
|
2018-01-06 06:50:48 +00:00
|
|
|
return cm.setPreprocessor((style.usercssData || {}).preprocessor);
|
2017-09-13 09:33:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function updateTitle() {
|
2017-11-26 13:04:03 +00:00
|
|
|
const newTitle = (dirty.isDirty() ? '* ' : '') +
|
2018-08-07 16:56:24 +00:00
|
|
|
(style.id ? style.name : t('addStyleTitle'));
|
2017-11-26 13:04:03 +00:00
|
|
|
if (document.title !== newTitle) {
|
|
|
|
document.title = newTitle;
|
2017-10-08 15:26:55 +00:00
|
|
|
}
|
2017-09-11 16:09:25 +00:00
|
|
|
}
|
|
|
|
|
2017-11-26 21:45:21 +00:00
|
|
|
function replaceStyle(newStyle, codeIsUpdated) {
|
|
|
|
const sameCode = newStyle.sourceCode === cm.getValue();
|
|
|
|
if (sameCode) {
|
|
|
|
savedGeneration = cm.changeGeneration();
|
|
|
|
dirty.clear('sourceGeneration');
|
2017-10-08 15:26:55 +00:00
|
|
|
}
|
2017-11-26 21:45:21 +00:00
|
|
|
if (codeIsUpdated === false || sameCode) {
|
2017-11-29 10:34:00 +00:00
|
|
|
updateEnvironment();
|
2017-11-26 21:45:21 +00:00
|
|
|
dirty.clear('enabled');
|
2018-11-07 06:09:29 +00:00
|
|
|
updateLivePreview();
|
2017-11-26 21:45:21 +00:00
|
|
|
return;
|
2017-09-11 16:09:25 +00:00
|
|
|
}
|
2017-11-29 10:34:00 +00:00
|
|
|
|
2017-11-26 21:45:21 +00:00
|
|
|
Promise.resolve(messageBox.confirm(t('styleUpdateDiscardChanges'))).then(ok => {
|
2018-01-05 10:20:46 +00:00
|
|
|
if (!ok) return;
|
2017-11-29 10:34:00 +00:00
|
|
|
updateEnvironment();
|
2017-11-26 21:45:21 +00:00
|
|
|
if (!sameCode) {
|
|
|
|
const cursor = cm.getCursor();
|
|
|
|
cm.setValue(style.sourceCode);
|
|
|
|
cm.setCursor(cursor);
|
|
|
|
savedGeneration = cm.changeGeneration();
|
|
|
|
}
|
2018-11-07 06:09:29 +00:00
|
|
|
if (sameCode) {
|
|
|
|
// the code is same but the environment is changed
|
|
|
|
updateLivePreview();
|
|
|
|
}
|
2017-11-26 21:45:21 +00:00
|
|
|
dirty.clear();
|
|
|
|
});
|
2017-11-29 10:34:00 +00:00
|
|
|
|
|
|
|
function updateEnvironment() {
|
|
|
|
if (style.id !== newStyle.id) {
|
|
|
|
history.replaceState({}, '', `?id=${newStyle.id}`);
|
|
|
|
}
|
|
|
|
sessionStorage.justEditedStyleId = newStyle.id;
|
2018-11-07 06:09:29 +00:00
|
|
|
Object.assign(style, newStyle);
|
2018-01-10 18:56:14 +00:00
|
|
|
$('#preview-label').classList.remove('hidden');
|
2017-11-29 10:34:00 +00:00
|
|
|
updateMeta();
|
2018-11-07 06:09:29 +00:00
|
|
|
livePreview.show(Boolean(style.id));
|
2017-11-29 10:34:00 +00:00
|
|
|
}
|
2017-11-09 06:07:06 +00:00
|
|
|
}
|
|
|
|
|
2017-09-11 16:09:25 +00:00
|
|
|
function toggleStyle() {
|
|
|
|
const value = !style.enabled;
|
|
|
|
dirty.modify('enabled', style.enabled, value);
|
|
|
|
style.enabled = value;
|
2017-11-08 23:26:51 +00:00
|
|
|
updateMeta();
|
2018-01-14 14:40:09 +00:00
|
|
|
$('#enabled').dispatchEvent(new Event('change', {bubbles: true}));
|
2017-09-11 16:09:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function save() {
|
2018-01-05 10:20:46 +00:00
|
|
|
if (!dirty.isDirty()) return;
|
2017-12-23 22:50:53 +00:00
|
|
|
const code = cm.getValue();
|
2018-08-18 20:17:20 +00:00
|
|
|
return ensureUniqueStyle(code)
|
2018-11-07 06:09:29 +00:00
|
|
|
.then(() => API.editSaveUsercss({
|
2017-09-18 03:34:12 +00:00
|
|
|
id: style.id,
|
|
|
|
enabled: style.enabled,
|
2017-12-23 22:50:53 +00:00
|
|
|
sourceCode: code,
|
2017-09-18 03:34:12 +00:00
|
|
|
}))
|
2018-11-07 06:09:29 +00:00
|
|
|
.then(replaceStyle)
|
2017-09-11 16:09:25 +00:00
|
|
|
.catch(err => {
|
2018-08-18 20:17:20 +00:00
|
|
|
if (err.handled) return;
|
2018-11-07 06:09:29 +00:00
|
|
|
if (err.code === 'missingMandatory' && err.args.includes('name')) {
|
2017-11-26 13:04:03 +00:00
|
|
|
messageBox.confirm(t('usercssReplaceTemplateConfirmation')).then(ok => ok &&
|
2018-01-01 17:02:49 +00:00
|
|
|
chromeSync.setLZValue('usercssTemplate', code)
|
|
|
|
.then(() => chromeSync.getLZValue('usercssTemplate'))
|
2017-12-23 22:50:53 +00:00
|
|
|
.then(saved => saved !== code && messageBox.alert(t('syncStorageErrorSaving'))));
|
2017-11-26 13:04:03 +00:00
|
|
|
return;
|
|
|
|
}
|
2017-11-27 03:54:59 +00:00
|
|
|
const contents = Array.isArray(err) ?
|
2017-12-03 21:12:09 +00:00
|
|
|
$create('pre', err.join('\n')) :
|
2018-11-07 06:09:29 +00:00
|
|
|
[err.message || String(err)];
|
2017-11-09 07:55:06 +00:00
|
|
|
if (Number.isInteger(err.index)) {
|
|
|
|
const pos = cm.posFromIndex(err.index);
|
|
|
|
contents[0] += ` (line ${pos.line + 1} col ${pos.ch + 1})`;
|
2017-12-03 21:12:09 +00:00
|
|
|
contents.push($create('pre', drawLinePointer(pos)));
|
2017-11-09 07:55:06 +00:00
|
|
|
}
|
2018-03-11 13:31:25 +00:00
|
|
|
messageBox.alert(contents, 'pre');
|
2017-09-11 16:09:25 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-08-18 20:17:20 +00:00
|
|
|
function ensureUniqueStyle(code) {
|
|
|
|
return style.id ? Promise.resolve() :
|
|
|
|
API.buildUsercss({
|
|
|
|
sourceCode: code,
|
|
|
|
checkDup: true,
|
|
|
|
metaOnly: true,
|
|
|
|
}).then(({dup}) => {
|
|
|
|
if (dup) {
|
|
|
|
messageBox.alert(t('usercssAvoidOverwriting'), 'danger', t('genericError'));
|
|
|
|
return Promise.reject({handled: true});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-01-05 10:20:46 +00:00
|
|
|
function drawLinePointer(pos) {
|
|
|
|
const SIZE = 60;
|
|
|
|
const line = cm.getLine(pos.line);
|
|
|
|
const numTabs = pos.ch + 1 - line.slice(0, pos.ch + 1).replace(/\t/g, '').length;
|
|
|
|
const pointer = ' '.repeat(pos.ch) + '^';
|
|
|
|
const start = Math.max(Math.min(pos.ch - SIZE / 2, line.length - SIZE), 0);
|
|
|
|
const end = Math.min(Math.max(pos.ch + SIZE / 2, SIZE), line.length);
|
|
|
|
const leftPad = start !== 0 ? '...' : '';
|
|
|
|
const rightPad = end !== line.length ? '...' : '';
|
|
|
|
return (
|
|
|
|
leftPad +
|
|
|
|
line.slice(start, end).replace(/\t/g, ' '.repeat(cm.options.tabSize)) +
|
|
|
|
rightPad +
|
|
|
|
'\n' +
|
|
|
|
' '.repeat(leftPad.length + numTabs * cm.options.tabSize) +
|
|
|
|
pointer.slice(start, end)
|
|
|
|
);
|
2017-10-16 08:08:13 +00:00
|
|
|
}
|
|
|
|
|
2017-12-02 15:29:12 +00:00
|
|
|
function nextPrevMozDocument(cm, dir) {
|
2017-12-03 00:52:49 +00:00
|
|
|
const MOZ_DOC = '@-moz-document';
|
2017-12-02 15:29:12 +00:00
|
|
|
const cursor = cm.getCursor();
|
2017-12-03 00:52:49 +00:00
|
|
|
const usePrevLine = dir < 0 && cursor.ch <= MOZ_DOC.length;
|
|
|
|
let line = cursor.line + (usePrevLine ? -1 : 0);
|
|
|
|
let start = usePrevLine ? 1e9 : cursor.ch + (dir > 0 ? 1 : -MOZ_DOC.length);
|
2017-12-02 15:29:12 +00:00
|
|
|
let found;
|
|
|
|
if (dir > 0) {
|
2017-12-03 00:52:49 +00:00
|
|
|
cm.doc.iter(cursor.line, cm.doc.size, goFind);
|
2017-12-02 15:29:12 +00:00
|
|
|
if (!found && cursor.line > 0) {
|
2017-12-03 00:52:49 +00:00
|
|
|
line = 0;
|
|
|
|
cm.doc.iter(0, cursor.line + 1, goFind);
|
2017-12-02 15:29:12 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
let handle, parentLines;
|
|
|
|
let passesRemain = line < cm.doc.size - 1 ? 2 : 1;
|
2017-12-03 00:52:49 +00:00
|
|
|
let stopAtLine = 0;
|
2017-12-02 15:29:12 +00:00
|
|
|
while (passesRemain--) {
|
|
|
|
let indexInParent = 0;
|
2017-12-03 00:52:49 +00:00
|
|
|
while (line >= stopAtLine) {
|
2017-12-02 15:29:12 +00:00
|
|
|
if (!indexInParent--) {
|
|
|
|
handle = cm.getLineHandle(line);
|
|
|
|
parentLines = handle.parent.lines;
|
|
|
|
indexInParent = parentLines.indexOf(handle);
|
|
|
|
} else {
|
|
|
|
handle = parentLines[indexInParent];
|
|
|
|
}
|
2017-12-03 00:52:49 +00:00
|
|
|
if (goFind(handle)) {
|
2017-12-02 15:29:12 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2017-12-03 00:52:49 +00:00
|
|
|
line = cm.doc.size - 1;
|
|
|
|
stopAtLine = cursor.line;
|
2017-12-02 15:29:12 +00:00
|
|
|
}
|
|
|
|
}
|
2017-12-03 00:52:49 +00:00
|
|
|
function goFind({text}) {
|
|
|
|
// use the initial 'start' on cursor row...
|
|
|
|
let ch = start;
|
|
|
|
// ...and reset it for the rest
|
|
|
|
start = dir > 0 ? 0 : 1e9;
|
|
|
|
while (true) {
|
|
|
|
// indexOf is 1000x faster than toLowerCase().indexOf() so we're trying it first
|
|
|
|
ch = dir > 0 ? text.indexOf('@-', ch) : text.lastIndexOf('@-', ch);
|
|
|
|
if (ch < 0) {
|
|
|
|
line += dir;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (text.substr(ch, MOZ_DOC.length).toLowerCase() === MOZ_DOC &&
|
|
|
|
cm.getTokenTypeAt({line, ch: ch + 1}) === 'def') {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
ch += dir * 3;
|
|
|
|
}
|
|
|
|
cm.setCursor(line, ch);
|
|
|
|
if (cm.cursorCoords().bottom > cm.display.scroller.clientHeight - 100) {
|
|
|
|
const margin = Math.min(100, cm.display.scroller.clientHeight / 4);
|
|
|
|
line += prefs.get('editor.appliesToLineWidget') ? 1 : 0;
|
|
|
|
cm.scrollIntoView({line, ch}, margin);
|
2017-12-02 15:29:12 +00:00
|
|
|
}
|
2017-12-03 00:52:49 +00:00
|
|
|
found = true;
|
|
|
|
return true;
|
2017-12-02 15:29:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-28 04:01:43 +00:00
|
|
|
function headerOnScroll({target, deltaY, deltaMode, shiftKey}) {
|
|
|
|
while ((target = target.parentElement)) {
|
|
|
|
if (deltaY < 0 && target.scrollTop ||
|
|
|
|
deltaY > 0 && target.scrollTop + target.clientHeight < target.scrollHeight) {
|
|
|
|
return;
|
|
|
|
}
|
2017-12-07 01:36:46 +00:00
|
|
|
}
|
|
|
|
cm.display.scroller.scrollTop +=
|
|
|
|
// WheelEvent.DOM_DELTA_LINE
|
2018-08-24 11:31:29 +00:00
|
|
|
deltaMode === 1 ? deltaY * cm.defaultTextHeight() :
|
2017-12-07 01:36:46 +00:00
|
|
|
// WheelEvent.DOM_DELTA_PAGE
|
|
|
|
deltaMode === 2 || shiftKey ? Math.sign(deltaY) * cm.display.scroller.clientHeight :
|
|
|
|
// WheelEvent.DOM_DELTA_PIXEL
|
|
|
|
deltaY;
|
|
|
|
}
|
|
|
|
|
2018-01-05 10:20:46 +00:00
|
|
|
function getModeName() {
|
|
|
|
const mode = cm.doc.mode;
|
2018-04-19 08:12:23 +00:00
|
|
|
if (!mode) return '';
|
|
|
|
return (mode.name || mode || '') +
|
|
|
|
(mode.helperType || '');
|
2018-01-05 10:20:46 +00:00
|
|
|
}
|
|
|
|
|
2017-09-19 00:49:38 +00:00
|
|
|
return {
|
|
|
|
replaceStyle,
|
|
|
|
isDirty: dirty.isDirty,
|
2017-10-16 08:08:13 +00:00
|
|
|
getStyle: () => style,
|
2018-11-07 06:09:29 +00:00
|
|
|
getEditors: () => [cm],
|
|
|
|
scrollToEditor: () => {},
|
|
|
|
getStyleId: () => style.id,
|
|
|
|
getEditorTitle: () => '',
|
|
|
|
save,
|
|
|
|
toggleStyle,
|
|
|
|
prevEditor: cm => nextPrevMozDocument(cm, -1),
|
|
|
|
nextEditor: cm => nextPrevMozDocument(cm, 1),
|
|
|
|
closestVisible: () => cm,
|
|
|
|
getSearchableInputs: () => []
|
2017-09-19 00:49:38 +00:00
|
|
|
};
|
2017-09-11 16:09:25 +00:00
|
|
|
}
|