Fixed (hacked) a weird iOS safari bug for read-only mode
parent
61d5f9d460
commit
f594be7cbc
|
@ -655,6 +655,20 @@ export class Editor {
|
||||||
contentDOM.setAttribute("autocorrect", "on");
|
contentDOM.setAttribute("autocorrect", "on");
|
||||||
contentDOM.setAttribute("autocapitalize", "on");
|
contentDOM.setAttribute("autocapitalize", "on");
|
||||||
contentDOM.setAttribute("contenteditable", readOnly ? "false" : "true");
|
contentDOM.setAttribute("contenteditable", readOnly ? "false" : "true");
|
||||||
|
|
||||||
|
if (isMobileSafari() && readOnly) {
|
||||||
|
console.log("Safari read only hack");
|
||||||
|
contentDOM.classList.add("ios-safari-readonly");
|
||||||
|
} else {
|
||||||
|
contentDOM.classList.remove("ios-safari-readonly");
|
||||||
|
}
|
||||||
|
|
||||||
|
function isMobileSafari() {
|
||||||
|
return (
|
||||||
|
navigator.userAgent.match(/(iPod|iPhone|iPad)/) &&
|
||||||
|
navigator.userAgent.match(/AppleWebKit/)
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private restoreState(pageName: string) {
|
private restoreState(pageName: string) {
|
||||||
|
|
|
@ -21,48 +21,49 @@ function wrapLines(view: EditorView, wrapElements: WrapElement[]) {
|
||||||
const doc = view.state.doc;
|
const doc = view.state.doc;
|
||||||
// Disabling the visible ranges for now, because it may be a bit buggy.
|
// Disabling the visible ranges for now, because it may be a bit buggy.
|
||||||
// RISK: this may actually become slow for large documents.
|
// RISK: this may actually become slow for large documents.
|
||||||
// for (let { from, to } of view.visibleRanges) {
|
for (let { from, to } of view.visibleRanges) {
|
||||||
syntaxTree(view.state).iterate({
|
syntaxTree(view.state).iterate({
|
||||||
// from,
|
from,
|
||||||
// to,
|
to,
|
||||||
enter: ({ type, from, to }) => {
|
enter: ({ type, from, to }) => {
|
||||||
for (let wrapElement of wrapElements) {
|
for (let wrapElement of wrapElements) {
|
||||||
if (type.name == wrapElement.selector) {
|
if (type.name == wrapElement.selector) {
|
||||||
if (wrapElement.nesting) {
|
|
||||||
elementStack.push(type.name);
|
|
||||||
}
|
|
||||||
const bodyText = doc.sliceString(from, to);
|
|
||||||
let idx = from;
|
|
||||||
for (let line of bodyText.split("\n")) {
|
|
||||||
let cls = wrapElement.class;
|
|
||||||
if (wrapElement.nesting) {
|
if (wrapElement.nesting) {
|
||||||
cls = `${cls} ${cls}-${elementStack.length}`;
|
elementStack.push(type.name);
|
||||||
|
}
|
||||||
|
const bodyText = doc.sliceString(from, to);
|
||||||
|
let idx = from;
|
||||||
|
for (let line of bodyText.split("\n")) {
|
||||||
|
let cls = wrapElement.class;
|
||||||
|
if (wrapElement.nesting) {
|
||||||
|
cls = `${cls} ${cls}-${elementStack.length}`;
|
||||||
|
}
|
||||||
|
widgets.push(
|
||||||
|
Decoration.line({
|
||||||
|
class: cls,
|
||||||
|
}).range(doc.lineAt(idx).from)
|
||||||
|
);
|
||||||
|
idx += line.length + 1;
|
||||||
}
|
}
|
||||||
widgets.push(
|
|
||||||
Decoration.line({
|
|
||||||
class: cls,
|
|
||||||
}).range(doc.lineAt(idx).from)
|
|
||||||
);
|
|
||||||
idx += line.length + 1;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
},
|
leave({ type }) {
|
||||||
leave({ type }) {
|
for (let wrapElement of wrapElements) {
|
||||||
for (let wrapElement of wrapElements) {
|
if (type.name == wrapElement.selector && wrapElement.nesting) {
|
||||||
if (type.name == wrapElement.selector && wrapElement.nesting) {
|
elementStack.pop();
|
||||||
elementStack.pop();
|
}
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
},
|
});
|
||||||
});
|
}
|
||||||
// }
|
|
||||||
// Widgets have to be sorted by `from` in ascending order
|
// Widgets have to be sorted by `from` in ascending order
|
||||||
widgets = widgets.sort((a, b) => {
|
widgets = widgets.sort((a, b) => {
|
||||||
return a.from < b.from ? -1 : 1;
|
return a.from < b.from ? -1 : 1;
|
||||||
});
|
});
|
||||||
return Decoration.set(widgets);
|
return Decoration.set(widgets);
|
||||||
}
|
}
|
||||||
|
|
||||||
export const lineWrapper = (wrapElements: WrapElement[]) =>
|
export const lineWrapper = (wrapElements: WrapElement[]) =>
|
||||||
ViewPlugin.fromClass(
|
ViewPlugin.fromClass(
|
||||||
class {
|
class {
|
||||||
|
|
|
@ -16,6 +16,11 @@
|
||||||
outline: none !important;
|
outline: none !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Weird hack to readjust iOS's safari font-size when contenteditable is disabled
|
||||||
|
.ios-safari-readonly {
|
||||||
|
font-size: 60%;
|
||||||
|
}
|
||||||
|
|
||||||
// Indentation of follow-up lines
|
// Indentation of follow-up lines
|
||||||
@mixin lineOverflow($baseIndent) {
|
@mixin lineOverflow($baseIndent) {
|
||||||
text-indent: -1 * ($baseIndent + 2ch);
|
text-indent: -1 * ($baseIndent + 2ch);
|
||||||
|
|
|
@ -296,12 +296,13 @@
|
||||||
background-color: rgba(77, 141, 255, 0.07);
|
background-color: rgba(77, 141, 255, 0.07);
|
||||||
border-radius: 5px;
|
border-radius: 5px;
|
||||||
padding: 0 5px;
|
padding: 0 5px;
|
||||||
|
white-space: nowrap;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
}
|
}
|
||||||
|
|
||||||
.sb-wiki-link {
|
.sb-wiki-link {
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
color: #a8abbd;
|
color: #8f96c2;
|
||||||
}
|
}
|
||||||
|
|
||||||
.sb-task-marker {
|
.sb-task-marker {
|
||||||
|
|
Loading…
Reference in New Issue