[evolution/wip/mcrha/webkit-jsc-api] Limit indent level to 10
- From: Milan Crha <mcrha src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution/wip/mcrha/webkit-jsc-api] Limit indent level to 10
- Date: Mon, 3 Feb 2020 16:22:43 +0000 (UTC)
commit d36ef02cf8bfcf5f70358244646411871f711603
Author: Milan Crha <mcrha redhat com>
Date: Mon Feb 3 17:24:33 2020 +0100
Limit indent level to 10
data/webkit/e-editor.js | 56 ++++++++++++++---------------
src/e-util/e-content-editor.c | 30 ++++++++--------
src/e-util/e-content-editor.h | 2 +-
src/e-util/e-html-editor-actions.c | 36 +++++++++++++++++--
src/e-util/e-html-editor-actions.h | 2 ++
src/e-util/e-html-editor.h | 2 ++
src/modules/webkit-editor/e-webkit-editor.c | 28 +++++++--------
7 files changed, 93 insertions(+), 63 deletions(-)
---
diff --git a/data/webkit/e-editor.js b/data/webkit/e-editor.js
index 1333523252..0873c8bb59 100644
--- a/data/webkit/e-editor.js
+++ b/data/webkit/e-editor.js
@@ -113,7 +113,7 @@ var EvoEditor = {
bgColor : null,
fontSize : null,
fontFamily : null,
- indented : false,
+ indentLevel : 0,
bodyFgColor : null,
bodyBgColor : null,
bodyLinkColor : null,
@@ -277,13 +277,11 @@ EvoEditor.maybeUpdateFormattingState = function(force)
script : 0,
blockFormat : null,
fontSize : null,
- indented : null,
+ indentLevel : 0,
bgColor : null
};
- for (parent = baseElem; parent && !(parent == document.body) && (
- obj.script == 0 || obj.blockFormat == null || obj.fontSize == null || obj.indented == null ||
obj.bgColor == null);
- parent = parent.parentElement) {
+ for (parent = baseElem; parent && !(parent === document.body); parent = parent.parentElement) {
if (obj.script == 0) {
if (parent.tagName == "SUB")
obj.script = -1;
@@ -332,33 +330,31 @@ EvoEditor.maybeUpdateFormattingState = function(force)
}
}
- if (obj.indented == null) {
- var dir = window.getComputedStyle(parent).direction;
+ var dir = window.getComputedStyle(parent).direction;
- if (dir == "rtl") {
- tmp = parent.style.marginRight;
- if (tmp && tmp.endsWith("ch")) {
- tmp = parseInt(tmp.slice(0, -2));
- } else {
- tmp = "";
- }
- } else { // "ltr" or other
- tmp = parent.style.marginLeft;
- if (tmp && tmp.endsWith("ch")) {
- tmp = parseInt(tmp.slice(0, -2));
- } else {
- tmp = "";
- }
+ if (dir == "rtl") {
+ tmp = parent.style.marginRight;
+ if (tmp && tmp.endsWith("ch")) {
+ tmp = parseInt(tmp.slice(0, -2));
+ } else {
+ tmp = "";
}
-
- if (Number.isInteger(tmp)) {
- obj.indented = tmp > 0;
+ } else { // "ltr" or other
+ tmp = parent.style.marginLeft;
+ if (tmp && tmp.endsWith("ch")) {
+ tmp = parseInt(tmp.slice(0, -2));
+ } else {
+ tmp = "";
}
+ }
- if (parent.tagName == "UL" || parent.tagName == "OL")
- obj.indented = true;
+ if (Number.isInteger(tmp) && tmp > 0) {
+ obj.indentLevel += tmp / EvoEditor.TEXT_INDENT_SIZE;
}
+ if (parent.tagName == "UL" || parent.tagName == "OL")
+ obj.indentLevel++;
+
if (obj.bgColor == null && parent.style.backgroundColor != "") {
obj.bgColor = parent.style.backgroundColor;
}
@@ -385,10 +381,10 @@ EvoEditor.maybeUpdateFormattingState = function(force)
nchanges++;
}
- value = obj.indented == null ? false : obj.indented;
- if (force || value != EvoEditor.formattingState.indented) {
- EvoEditor.formattingState.indented = value;
- changes["indented"] = value;
+ value = obj.indentLevel;
+ if (force || value != EvoEditor.formattingState.indentLevel) {
+ EvoEditor.formattingState.indentLevel = value;
+ changes["indentLevel"] = value;
nchanges++;
}
diff --git a/src/e-util/e-content-editor.c b/src/e-util/e-content-editor.c
index 089dcfc568..2252a239f6 100644
--- a/src/e-util/e-content-editor.c
+++ b/src/e-util/e-content-editor.c
@@ -299,18 +299,18 @@ e_content_editor_default_init (EContentEditorInterface *iface)
G_PARAM_STATIC_STRINGS));
/**
- * EContentEditor:indented
+ * EContentEditor:indent-level
*
- * Holds whether current paragraph is indented. This does not include
+ * Holds current paragraph indent level. This does not include
* citations.
*/
g_object_interface_install_property (
iface,
- g_param_spec_boolean (
- "indented",
+ g_param_spec_int (
+ "indent-level",
NULL,
NULL,
- FALSE,
+ 0, E_HTML_EDITOR_MAX_INDENT_LEVEL, 0,
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS));
@@ -724,24 +724,24 @@ e_content_editor_can_redo (EContentEditor *editor)
}
/**
- * e_content_editor_is_indented:
+ * e_content_editor_indent_level:
* @editor: an #EContentEditor
*
- * Returns whether the current paragraph is indented. This does not include
- * citations.
+ * Returns the indent level for the current selection/caret position.
+ * This does not include citations.
*
- * Returns: %TRUE when current paragraph is indented, %FALSE otherwise.
+ * Returns: the indent level.
*
- * Since: 3.22
+ * Since: 3.38
**/
-gboolean
-e_content_editor_is_indented (EContentEditor *editor)
+gint
+e_content_editor_indent_level (EContentEditor *editor)
{
- gboolean value = FALSE;
+ gint value = 0;
- g_return_val_if_fail (E_IS_CONTENT_EDITOR (editor), FALSE);
+ g_return_val_if_fail (E_IS_CONTENT_EDITOR (editor), 0);
- g_object_get (G_OBJECT (editor), "indented", &value, NULL);
+ g_object_get (G_OBJECT (editor), "indent-level", &value, NULL);
return value;
}
diff --git a/src/e-util/e-content-editor.h b/src/e-util/e-content-editor.h
index 245f2d58fc..ae00b147f4 100644
--- a/src/e-util/e-content-editor.h
+++ b/src/e-util/e-content-editor.h
@@ -433,7 +433,7 @@ gboolean e_content_editor_can_copy (EContentEditor *editor);
gboolean e_content_editor_can_paste (EContentEditor *editor);
gboolean e_content_editor_can_undo (EContentEditor *editor);
gboolean e_content_editor_can_redo (EContentEditor *editor);
-gboolean e_content_editor_is_indented (EContentEditor *editor);
+gint e_content_editor_indent_level (EContentEditor *editor);
gboolean e_content_editor_get_spell_check_enabled
(EContentEditor *editor);
void e_content_editor_set_spell_check_enabled
diff --git a/src/e-util/e-html-editor-actions.c b/src/e-util/e-html-editor-actions.c
index 1e7d0671c7..56b885e886 100644
--- a/src/e-util/e-html-editor-actions.c
+++ b/src/e-util/e-html-editor-actions.c
@@ -2214,6 +2214,28 @@ e_html_editor_content_editor_font_name_to_combo_box (GBinding *binding,
return TRUE;
}
+static gboolean
+e_html_editor_indent_level_to_bool_indent_cb (GBinding *binding,
+ const GValue *from_value,
+ GValue *to_value,
+ gpointer user_data)
+{
+ g_value_set_boolean (to_value, g_value_get_int (from_value) < E_HTML_EDITOR_MAX_INDENT_LEVEL);
+
+ return TRUE;
+}
+
+static gboolean
+e_html_editor_indent_level_to_bool_unindent_cb (GBinding *binding,
+ const GValue *from_value,
+ GValue *to_value,
+ gpointer user_data)
+{
+ g_value_set_boolean (to_value, g_value_get_int (from_value) > 0);
+
+ return TRUE;
+}
+
void
editor_actions_bind (EHTMLEditor *editor)
{
@@ -2278,10 +2300,18 @@ editor_actions_bind (EHTMLEditor *editor)
cnt_editor, "block-format",
ACTION (STYLE_NORMAL), "current-value",
G_BINDING_SYNC_CREATE | G_BINDING_BIDIRECTIONAL);
- e_binding_bind_property (
- cnt_editor, "indented",
+ e_binding_bind_property_full (
+ cnt_editor, "indent-level",
+ ACTION (INDENT), "sensitive",
+ G_BINDING_SYNC_CREATE,
+ e_html_editor_indent_level_to_bool_indent_cb,
+ NULL, NULL, NULL);
+ e_binding_bind_property_full (
+ cnt_editor, "indent-level",
ACTION (UNINDENT), "sensitive",
- G_BINDING_SYNC_CREATE);
+ G_BINDING_SYNC_CREATE,
+ e_html_editor_indent_level_to_bool_unindent_cb,
+ NULL, NULL, NULL);
e_binding_bind_property (
cnt_editor, "italic",
ACTION (ITALIC), "active",
diff --git a/src/e-util/e-html-editor-actions.h b/src/e-util/e-html-editor-actions.h
index ecb5922c7c..a7898168bb 100644
--- a/src/e-util/e-html-editor-actions.h
+++ b/src/e-util/e-html-editor-actions.h
@@ -83,6 +83,8 @@
E_HTML_EDITOR_ACTION ((editor), "format-menu")
#define E_HTML_EDITOR_ACTION_FORMAT_TEXT(editor) \
E_HTML_EDITOR_ACTION ((editor), "format-text")
+#define E_HTML_EDITOR_ACTION_INDENT(editor) \
+ E_HTML_EDITOR_ACTION ((editor), "indent")
#define E_HTML_EDITOR_ACTION_INSERT_EMOTICON(editor) \
E_HTML_EDITOR_ACTION ((editor), "insert-emoticon")
#define E_HTML_EDITOR_ACTION_INSERT_EMOJI(editor) \
diff --git a/src/e-util/e-html-editor.h b/src/e-util/e-html-editor.h
index ed3e078b66..8be1af19ea 100644
--- a/src/e-util/e-html-editor.h
+++ b/src/e-util/e-html-editor.h
@@ -49,6 +49,8 @@
(G_TYPE_INSTANCE_GET_CLASS \
((obj), E_TYPE_HTML_EDITOR, EHTMLEditorClass))
+#define E_HTML_EDITOR_MAX_INDENT_LEVEL 10
+
G_BEGIN_DECLS
typedef struct _EHTMLEditor EHTMLEditor;
diff --git a/src/modules/webkit-editor/e-webkit-editor.c b/src/modules/webkit-editor/e-webkit-editor.c
index f9e6a7c01c..0968ffe5a1 100644
--- a/src/modules/webkit-editor/e-webkit-editor.c
+++ b/src/modules/webkit-editor/e-webkit-editor.c
@@ -59,7 +59,7 @@ enum {
PROP_FONT_COLOR,
PROP_FONT_NAME,
PROP_FONT_SIZE,
- PROP_INDENTED,
+ PROP_INDENT_LEVEL,
PROP_ITALIC,
PROP_STRIKETHROUGH,
PROP_SUBSCRIPT,
@@ -88,7 +88,7 @@ struct _EWebKitEditorPrivate {
guint32 style_flags;
guint32 temporary_style_flags; /* that's for collapsed selection, format changes only after something
is typed */
- gboolean is_indented;
+ gint indent_level;
GdkRGBA *background_color;
GdkRGBA *font_color;
@@ -943,19 +943,19 @@ formatting_changed_cb (WebKitUserContentManager *manager,
g_object_notify (object, "block-format");
changed = FALSE;
- jsc_value = jsc_value_object_get_property (jsc_params, "indented");
- if (jsc_value && jsc_value_is_boolean (jsc_value)) {
- gboolean value = jsc_value_to_boolean (jsc_value);
+ jsc_value = jsc_value_object_get_property (jsc_params, "indentLevel");
+ if (jsc_value && jsc_value_is_number (jsc_value)) {
+ gint value = jsc_value_to_int32 (jsc_value);
- if ((value ? 1: 0) != (wk_editor->priv->is_indented ? 1 : 0)) {
- wk_editor->priv->is_indented = value;
+ if (value != wk_editor->priv->indent_level) {
+ wk_editor->priv->indent_level = value;
changed = TRUE;
}
}
g_clear_object (&jsc_value);
if (changed || forced)
- g_object_notify (object, "indented");
+ g_object_notify (object, "indent-level");
#define update_style_flag(_flag, _set) \
changed = (wk_editor->priv->style_flags & (_flag)) != ((_set) ? (_flag) : 0); \
@@ -2350,11 +2350,11 @@ webkit_editor_selection_wrap (EContentEditor *editor)
}
static gboolean
-webkit_editor_selection_is_indented (EWebKitEditor *wk_editor)
+webkit_editor_get_indent_level (EWebKitEditor *wk_editor)
{
g_return_val_if_fail (E_IS_WEBKIT_EDITOR (wk_editor), FALSE);
- return wk_editor->priv->is_indented;
+ return wk_editor->priv->indent_level;
}
static void
@@ -4538,10 +4538,10 @@ webkit_editor_get_property (GObject *object,
E_WEBKIT_EDITOR (object)));
return;
- case PROP_INDENTED:
- g_value_set_boolean (
+ case PROP_INDENT_LEVEL:
+ g_value_set_int (
value,
- webkit_editor_selection_is_indented (
+ webkit_editor_get_indent_level (
E_WEBKIT_EDITOR (object)));
return;
@@ -5273,7 +5273,7 @@ e_webkit_editor_class_init (EWebKitEditorClass *class)
g_object_class_override_property (
object_class, PROP_FONT_SIZE, "font-size");
g_object_class_override_property (
- object_class, PROP_INDENTED, "indented");
+ object_class, PROP_INDENT_LEVEL, "indent-level");
g_object_class_override_property (
object_class, PROP_ITALIC, "italic");
g_object_class_override_property (
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]