a few fixes

This commit is contained in:
Jeremy Schomery 2017-07-19 20:48:34 +04:30 committed by tophf
parent 3ccdb555da
commit 3c298995f1

View File

@ -261,8 +261,11 @@ function initCodeMirror() {
// initialize global editor controls // initialize global editor controls
function optionsFromArray(parent, options) { function optionsFromArray(parent, options) {
options.map(opt => $element({tag: 'option', textContent: opt})) const fragment = document.createDocumentFragment();
.forEach(opt => parent.appendChild(opt)); for (const opt of options) {
fragment.appendChild($element({tag: 'option', textContent: opt}));
}
parent.appendChild(fragment);
} }
const themeControl = document.getElementById('editor.theme'); const themeControl = document.getElementById('editor.theme');
const themeList = localStorage.codeMirrorThemes; const themeList = localStorage.codeMirrorThemes;
@ -324,7 +327,7 @@ function acmeEventListener(event) {
setTimeout(() => { setTimeout(() => {
CodeMirror.setOption(option, value); CodeMirror.setOption(option, value);
themeLink.remove(); themeLink.remove();
document.getElementById('cm-theme2').id = 'cm-theme'; $('#cm-theme2').id = 'cm-theme';
}, 100); }, 100);
return; return;
} }
@ -1751,21 +1754,37 @@ function showKeyMapHelp() {
function filterTable(event) { function filterTable(event) {
const input = event.target; const input = event.target;
const query = stringAsRegExp(input.value, 'gi');
const col = input.parentNode.cellIndex; const col = input.parentNode.cellIndex;
inputs[1 - col].value = ''; inputs[1 - col].value = '';
table.tBodies[0].childNodes.forEach(row => { table.tBodies[0].childNodes.forEach(row => {
const cell = row.children[col]; const cell = row.children[col];
const html = cell.textContent.replace(query, '<mark>$&</mark>'); const text = cell.textContent;
const query = stringAsRegExp(input.value, 'gi');
const test = query.test(text);
row.style.display = input.value && test === false ? 'none' : '';
if (input.value && test) {
cell.textContent = ''; cell.textContent = '';
const div = tHTML(html, 'div'); let offset = 0;
while (div.childNodes.length > 0) { text.replace(query, (match, index) => {
cell.appendChild(div.childNodes[0]); if (index > offset) {
cell.appendChild(document.createTextNode(text.substring(offset, index)));
}
cell.appendChild($element({tag: 'mark', textContent: match}));
offset = index + match.length;
});
if (offset + 1 !== text.length) {
cell.appendChild(document.createTextNode(text.substring(offset)));
}
}
else {
cell.textContent = text;
} }
row.style.display = query.test(cell.textContent) ? '' : 'none';
// clear highlight from the other column // clear highlight from the other column
// cell = row.children[1 - col]; const otherCell = row.children[1 - col];
// cell.innerHTML = cell.textContent; if (otherCell.children.length) {
const text = otherCell.textContent;
otherCell.textContent = text;
}
}); });
} }
function mergeKeyMaps(merged, ...more) { function mergeKeyMaps(merged, ...more) {