[evolution/wip/mcrha/webkit-jsc-api] Plain text (not only) style changes
- From: Milan Crha <mcrha src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution/wip/mcrha/webkit-jsc-api] Plain text (not only) style changes
- Date: Mon, 3 Feb 2020 15:50:27 +0000 (UTC)
commit eeb90c38ed7a84e6f8780d79c63b772856c00d03
Author: Milan Crha <mcrha redhat com>
Date: Mon Feb 3 16:51:51 2020 +0100
Plain text (not only) style changes
data/webkit/e-editor.js | 58 +++++-
src/modules/webkit-editor/e-webkit-editor.c | 285 +++++++++++++++-------------
2 files changed, 205 insertions(+), 138 deletions(-)
---
diff --git a/data/webkit/e-editor.js b/data/webkit/e-editor.js
index efb608c29a..1333523252 100644
--- a/data/webkit/e-editor.js
+++ b/data/webkit/e-editor.js
@@ -1246,9 +1246,11 @@ EvoEditor.applyIndent = function(record, isUndo)
if (isUndo) {
child.style.marginLeft = change.beforeMarginLeft;
child.style.marginRight = change.beforeMarginRight;
+ child.style.width = change.beforeWidth;
} else {
child.style.marginLeft = change.afterMarginLeft;
child.style.marginRight = change.afterMarginRight;
+ child.style.width = change.afterWidth;
}
EvoEditor.removeEmptyStyleAttribute(child);
@@ -1285,6 +1287,7 @@ EvoEditor.Indent = function(increment)
change.path = EvoSelection.GetChildPath(parent, element);
change.beforeMarginLeft = element.style.marginLeft;
change.beforeMarginRight = element.style.marginRight;
+ change.beforeWidth = element.style.width;
}
traversar.record.changes[traversar.record.changes.length] = change;
@@ -1426,7 +1429,7 @@ EvoEditor.Indent = function(increment)
}
}
} else {
- var currValue = null, dir;
+ var currValue = null, dir, width;
dir = window.getComputedStyle(element).direction;
@@ -1446,11 +1449,24 @@ EvoEditor.Indent = function(increment)
currValue = 0;
}
+ width = 0;
+ if (element.style.width.endsWith("ch")) {
+ width = parseInt(element.style.width.slice(0, -2));
+ if (!Number.isInteger(width))
+ width = 0;
+ }
+
if (traversar.increment) {
+ if (width && width - EvoEditor.TEXT_INDENT_SIZE > 0)
+ width = width - EvoEditor.TEXT_INDENT_SIZE;
currValue = (currValue + EvoEditor.TEXT_INDENT_SIZE) + "ch";
} else if (currValue > EvoEditor.TEXT_INDENT_SIZE) {
+ if (width)
+ width = width + EvoEditor.TEXT_INDENT_SIZE;
currValue = (currValue - EvoEditor.TEXT_INDENT_SIZE) + "ch";
} else {
+ if (width)
+ width = width + currValue;
currValue = "";
}
@@ -1460,9 +1476,13 @@ EvoEditor.Indent = function(increment)
element.style.marginLeft = currValue;
}
+ if (width)
+ element.style.width = width + "ch";
+
if (change) {
change.afterMarginLeft = element.style.marginLeft;
change.afterMarginRight = element.style.marginRight;
+ change.afterWidth = element.style.width;
}
EvoEditor.removeEmptyStyleAttribute(element);
@@ -1639,6 +1659,15 @@ EvoEditor.beforeInputCb = function(inputEvent)
inputEvent.preventDefault();
}
+EvoEditor.emptyParagraphAsHtml = function()
+{
+ if (EvoEditor.mode == EvoEditor.MODE_PLAIN_TEXT) {
+ return "<div style=\"width:" + EvoEditor.NORMAL_PARAGRAPH_WIDTH + "ch;\"><br></div>";
+ } else {
+ return "<div><br></div>";
+ }
+}
+
EvoEditor.initializeContent = function()
{
// for backward compatibility
@@ -1651,7 +1680,7 @@ EvoEditor.initializeContent = function()
if (!document.body.firstChild) {
EvoUndoRedo.Disable();
try {
- document.body.innerHTML = "<div><br></div>";
+ document.body.innerHTML = EvoEditor.emptyParagraphAsHtml();
} finally {
EvoUndoRedo.Enable();
}
@@ -2362,18 +2391,39 @@ EvoEditor.AfterInputEvent = function(inputEvent, isWordDelim)
var selection = document.getSelection();
if (isInsertParagraph && selection.isCollapsed && selection.baseNode && selection.baseNode.tagName ==
"BODY") {
- document.execCommand("insertHTML", false, "<div><br></div>");
+ document.execCommand("insertHTML", false, EvoEditor.emptyParagraphAsHtml());
EvoUndoRedo.GroupTopRecords(2, "insertParagraph::withFormat");
return;
}
// make sure there's always a DIV in the body (like after 'select all' followed by 'delete')
if (!document.body.childNodes.length || (document.body.childNodes.length == 1 &&
document.body.childNodes[0].tagName == "BR")) {
- document.execCommand("insertHTML", false, "<div><br></div>");
+ document.execCommand("insertHTML", false, EvoEditor.emptyParagraphAsHtml());
EvoUndoRedo.GroupTopRecords(2, inputEvent.inputType + "::fillEmptyBody");
return;
}
+ if (isInsertParagraph && selection.isCollapsed && selection.baseNode && selection.baseNode.tagName ==
"DIV") {
+ // for example when moving away from ul/ol, the newly created
+ // paragraph can inherit styles from it, which is also negative text-indent
+ selection.baseNode.removeAttribute("style");
+
+ if (EvoEditor.mode == EvoEditor.MODE_PLAIN_TEXT) {
+ var node = selection.baseNode, citeLevel = 0;
+
+ while (node && node.tagName != "BODY") {
+ if (node.tagName == "BLOCKQUOTE")
+ citeLevel++;
+
+ node = node.parentElement;
+ }
+
+ if (citeLevel * 2 < EvoEditor.NORMAL_PARAGRAPH_WIDTH) {
+ selection.baseNode.style.width = (EvoEditor.NORMAL_PARAGRAPH_WIDTH -
citeLevel * 2) + "ch";
+ }
+ }
+ }
+
if ((!isInsertParagraph && inputEvent.inputType != "insertText") ||
(!(EvoEditor.MAGIC_LINKS && (isWordDelim || isInsertParagraph)) &&
!EvoEditor.MAGIC_SMILEYS)) {
diff --git a/src/modules/webkit-editor/e-webkit-editor.c b/src/modules/webkit-editor/e-webkit-editor.c
index 0e0d6f6bb4..f9e6a7c01c 100644
--- a/src/modules/webkit-editor/e-webkit-editor.c
+++ b/src/modules/webkit-editor/e-webkit-editor.c
@@ -1324,28 +1324,6 @@ webkit_editor_update_styles (EContentEditor *editor)
" outline: 1px dotted red;\n"
"}\n");
- g_string_append (
- stylesheet,
- "body[data-evo-plain-text] "
- "{\n"
- " font-family: Monospace; \n"
- "}\n");
-
- g_string_append (
- stylesheet,
- "[data-evo-paragraph] "
- "{\n"
- " white-space: pre-wrap; \n"
- "}\n");
-
- g_string_append (
- stylesheet,
- "body[data-evo-plain-text] [data-evo-paragraph] "
- "{\n"
- " word-wrap: break-word; \n"
- " word-break: break-word; \n"
- "}\n");
-
g_string_append_printf (
stylesheet,
".-x-evo-plaintext-table "
@@ -1362,49 +1340,159 @@ webkit_editor_update_styles (EContentEditor *editor)
" vertical-align: top;\n"
"}\n");
- g_string_append_printf (
- stylesheet,
- "body[data-evo-plain-text] ul "
- "{\n"
- " list-style: outside none;\n"
- " -webkit-padding-start: %dch; \n"
- "}\n", SPACES_PER_LIST_LEVEL);
+ if (wk_editor->priv->html_mode) {
+ g_string_append (
+ stylesheet,
+ "body ul > li.-x-evo-align-center,ol > li.-x-evo-align-center "
+ "{\n"
+ " list-style-position: inside;\n"
+ "}\n");
- g_string_append_printf (
- stylesheet,
- "body[data-evo-plain-text] ul > li "
- "{\n"
- " list-style-position: outside;\n"
- " text-indent: -%dch;\n"
- "}\n", SPACES_PER_LIST_LEVEL - 1);
+ g_string_append (
+ stylesheet,
+ "body ul > li.-x-evo-align-right, ol > li.-x-evo-align-right "
+ "{\n"
+ " list-style-position: inside;\n"
+ "}\n");
- g_string_append (
- stylesheet,
- "body[data-evo-plain-text] ul > li::before "
- "{\n"
- " content: \"*" UNICODE_NBSP "\";\n"
- "}\n");
+ g_string_append (
+ stylesheet,
+ "body "
+ "blockquote[type=cite] "
+ "{\n"
+ " padding: 0ch 1ch 0ch 1ch;\n"
+ " margin: 0ch;\n"
+ " border-width: 0px 2px 0px 2px;\n"
+ " border-style: none solid none solid;\n"
+ " border-radius: 2px;\n"
+ "}\n");
- g_string_append_printf (
- stylesheet,
- "body[data-evo-plain-text] ul.-x-evo-indented "
- "{\n"
- " -webkit-padding-start: %dch; \n"
- "}\n", SPACES_PER_LIST_LEVEL);
+ g_string_append_printf (
+ stylesheet,
+ "body "
+ "blockquote[type=cite] "
+ "{\n"
+ " border-color: %s;\n"
+ "}\n",
+ e_web_view_get_citation_color_for_level (1));
- g_string_append (
- stylesheet,
- "body:not([data-evo-plain-text]) ul > li.-x-evo-align-center,ol > li.-x-evo-align-center "
- "{\n"
- " list-style-position: inside;\n"
- "}\n");
+ g_string_append_printf (
+ stylesheet,
+ "body "
+ "blockquote[type=cite] "
+ "blockquote[type=cite] "
+ "{\n"
+ " border-color: %s;\n"
+ "}\n",
+ e_web_view_get_citation_color_for_level (2));
- g_string_append (
- stylesheet,
- "body:not([data-evo-plain-text]) ul > li.-x-evo-align-right, ol > li.-x-evo-align-right "
- "{\n"
- " list-style-position: inside;\n"
- "}\n");
+ g_string_append_printf (
+ stylesheet,
+ "body "
+ "blockquote[type=cite] "
+ "blockquote[type=cite] "
+ "blockquote[type=cite] "
+ "{\n"
+ " border-color: %s;\n"
+ "}\n",
+ e_web_view_get_citation_color_for_level (3));
+
+ g_string_append_printf (
+ stylesheet,
+ "body "
+ "blockquote[type=cite] "
+ "blockquote[type=cite] "
+ "blockquote[type=cite] "
+ "blockquote[type=cite] "
+ "{\n"
+ " border-color: %s;\n"
+ "}\n",
+ e_web_view_get_citation_color_for_level (4));
+
+ g_string_append_printf (
+ stylesheet,
+ "body "
+ "blockquote[type=cite] "
+ "blockquote[type=cite] "
+ "blockquote[type=cite] "
+ "blockquote[type=cite] "
+ "blockquote[type=cite] "
+ "{\n"
+ " border-color: %s;\n"
+ "}\n",
+ e_web_view_get_citation_color_for_level (5));
+ } else {
+ g_string_append (
+ stylesheet,
+ "body "
+ "{\n"
+ " font-family: Monospace; \n"
+ "}\n");
+
+ g_string_append_printf (
+ stylesheet,
+ "body ul "
+ "{\n"
+ " list-style: outside none;\n"
+ " -webkit-padding-start: %dch; \n"
+ "}\n", SPACES_PER_LIST_LEVEL);
+
+ g_string_append_printf (
+ stylesheet,
+ "body ul > li "
+ "{\n"
+ " list-style-position: outside;\n"
+ " text-indent: -%dch;\n"
+ "}\n", SPACES_PER_LIST_LEVEL - 1);
+
+ g_string_append (
+ stylesheet,
+ "body ul > li::before "
+ "{\n"
+ " content: \"*" UNICODE_NBSP "\";\n"
+ "}\n");
+
+ g_string_append (
+ stylesheet,
+ "body ul ul > li::before, "
+ "body ol ul > li::before "
+ "{\n"
+ " content: \"-" UNICODE_NBSP "\";\n"
+ "}\n");
+
+ g_string_append (
+ stylesheet,
+ "body ul ul ul > li::before, "
+ "body ol ul ul > li::before, "
+ "body ul ol ul > li::before, "
+ "body ol ol ul > li::before "
+ "{\n"
+ " content: \"+" UNICODE_NBSP "\";\n"
+ "}\n");
+
+ g_string_append (
+ stylesheet,
+ "body ul ul ul ul > li::before, "
+ "body ol ul ul ul > li::before, "
+ "body ul ol ul ul > li::before, "
+ "body ul ul ol ul > li::before, "
+ "body ol ol ul ul > li::before, "
+ "body ol ul ol ul > li::before, "
+ "body ul ol ol ul > li::before, "
+ "body ol ol ol ul > li::before "
+ "{\n"
+ " content: \"*" UNICODE_NBSP "\";\n"
+ "}\n");
+
+ g_string_append (
+ stylesheet,
+ "body div "
+ "{\n"
+ " word-wrap: break-word; \n"
+ " word-break: break-word; \n"
+ " white-space: pre-wrap; \n"
+ "}\n");
+ }
g_string_append_printf (
stylesheet,
@@ -1413,13 +1501,6 @@ webkit_editor_update_styles (EContentEditor *editor)
" -webkit-padding-start: %dch; \n"
"}\n", SPACES_ORDERED_LIST_FIRST_LEVEL);
- g_string_append_printf (
- stylesheet,
- "ol.-x-evo-indented "
- "{\n"
- " -webkit-padding-start: %dch; \n"
- "}\n", SPACES_PER_LIST_LEVEL);
-
g_string_append (
stylesheet,
"ol,ul "
@@ -1531,73 +1612,6 @@ webkit_editor_update_styles (EContentEditor *editor)
"}\n",
e_web_view_get_citation_color_for_level (5));
- g_string_append (
- stylesheet,
- "body:not([data-evo-plain-text]) "
- "blockquote[type=cite] "
- "{\n"
- " padding: 0ch 1ch 0ch 1ch;\n"
- " margin: 0ch;\n"
- " border-width: 0px 2px 0px 2px;\n"
- " border-style: none solid none solid;\n"
- " border-radius: 2px;\n"
- "}\n");
-
- g_string_append_printf (
- stylesheet,
- "body:not([data-evo-plain-text]) "
- "blockquote[type=cite] "
- "{\n"
- " border-color: %s;\n"
- "}\n",
- e_web_view_get_citation_color_for_level (1));
-
- g_string_append_printf (
- stylesheet,
- "body:not([data-evo-plain-text]) "
- "blockquote[type=cite] "
- "blockquote[type=cite] "
- "{\n"
- " border-color: %s;\n"
- "}\n",
- e_web_view_get_citation_color_for_level (2));
-
- g_string_append_printf (
- stylesheet,
- "body:not([data-evo-plain-text]) "
- "blockquote[type=cite] "
- "blockquote[type=cite] "
- "blockquote[type=cite] "
- "{\n"
- " border-color: %s;\n"
- "}\n",
- e_web_view_get_citation_color_for_level (3));
-
- g_string_append_printf (
- stylesheet,
- "body:not([data-evo-plain-text]) "
- "blockquote[type=cite] "
- "blockquote[type=cite] "
- "blockquote[type=cite] "
- "blockquote[type=cite] "
- "{\n"
- " border-color: %s;\n"
- "}\n",
- e_web_view_get_citation_color_for_level (4));
-
- g_string_append_printf (
- stylesheet,
- "body:not([data-evo-plain-text]) "
- "blockquote[type=cite] "
- "blockquote[type=cite] "
- "blockquote[type=cite] "
- "blockquote[type=cite] "
- "blockquote[type=cite] "
- "{\n"
- " border-color: %s;\n"
- "}\n",
- e_web_view_get_citation_color_for_level (5));
-
if (wk_editor->priv->visually_wrap_long_lines) {
g_string_append (
stylesheet,
@@ -1977,6 +1991,9 @@ webkit_editor_set_html_mode (EWebKitEditor *wk_editor,
e_web_view_jsc_run_script (WEBKIT_WEB_VIEW (wk_editor), wk_editor->priv->cancellable,
"EvoEditor.SetMode(EvoEditor.MODE_PLAIN_TEXT);");
}
+
+ webkit_editor_update_styles (E_CONTENT_EDITOR (wk_editor));
+ webkit_editor_style_updated_cb (wk_editor);
}
static void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]