diff options
Diffstat (limited to 'framework/qml')
-rw-r--r-- | framework/qml/TextEditor.qml | 9 | ||||
-rw-r--r-- | framework/qml/tests/tst_texteditor.qml | 32 |
2 files changed, 11 insertions, 30 deletions
diff --git a/framework/qml/TextEditor.qml b/framework/qml/TextEditor.qml index 7dd30625..bc50169e 100644 --- a/framework/qml/TextEditor.qml +++ b/framework/qml/TextEditor.qml | |||
@@ -24,9 +24,8 @@ import org.kube.framework 1.0 as Kube | |||
24 | 24 | ||
25 | FocusScope { | 25 | FocusScope { |
26 | id: root | 26 | id: root |
27 | property string text: "" | 27 | property string text: document.text |
28 | 28 | property bool htmlEnabled: document.containsFormatting | |
29 | property bool htmlEnabled: false | ||
30 | 29 | ||
31 | property alias bold: document.bold | 30 | property alias bold: document.bold |
32 | property alias italic: document.italic | 31 | property alias italic: document.italic |
@@ -46,10 +45,6 @@ FocusScope { | |||
46 | document: edit.textDocument | 45 | document: edit.textDocument |
47 | selectionStart: edit.selectionStart | 46 | selectionStart: edit.selectionStart |
48 | selectionEnd: edit.selectionEnd | 47 | selectionEnd: edit.selectionEnd |
49 | onTextChanged: { | ||
50 | root.htmlEnabled = containsFormatting(); | ||
51 | root.htmlEnabled ? root.text = htmlText : root.text = plainText | ||
52 | } | ||
53 | cursorPosition: edit.cursorPosition | 48 | cursorPosition: edit.cursorPosition |
54 | } | 49 | } |
55 | 50 | ||
diff --git a/framework/qml/tests/tst_texteditor.qml b/framework/qml/tests/tst_texteditor.qml index f80afe66..544270e5 100644 --- a/framework/qml/tests/tst_texteditor.qml +++ b/framework/qml/tests/tst_texteditor.qml | |||
@@ -33,41 +33,27 @@ TestCase { | |||
33 | Kube.TextEditor {} | 33 | Kube.TextEditor {} |
34 | } | 34 | } |
35 | 35 | ||
36 | function test_1initialText() { | 36 | property string htmlText: "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\"><html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">p, li { white-space: pre-wrap; }</style></head><body style=\" font-family:'Noto Sans'; font-size:9pt; font-weight:400; font-style:normal;\"><p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><b>Foobar</b><br>BarBar</p></body></html>" |
37 | var editor = createTemporaryObject(editorComponent, testCase, {initialText: "Foobar\nBarBar", htmlEnabled: false}) | 37 | property string plainText: "Foobar\nBarBar" |
38 | compare(editor.text, editor.initialText) | ||
39 | } | ||
40 | 38 | ||
41 | function test_2plainToHtmlConversion() { | 39 | function test_1initialText() { |
42 | var editor = createTemporaryObject(editorComponent, testCase, {initialText: "Foobar\nBarBar", htmlEnabled: false}) | 40 | var editor = createTemporaryObject(editorComponent, testCase, {initialText: plainText}) |
43 | editor.htmlEnabled = true | ||
44 | verify(editor.text.indexOf("<html>") !== -1) | ||
45 | //It's converted into two paragraphs, so we can't check as a single string | ||
46 | verify(editor.text.indexOf("Foobar") !== -1) | ||
47 | verify(editor.text.indexOf("BarBar") !== -1) | ||
48 | editor.htmlEnabled = false | ||
49 | compare(editor.text, editor.initialText) | 41 | compare(editor.text, editor.initialText) |
50 | |||
51 | editor.htmlEnabled = true | ||
52 | verify(editor.text.indexOf("<html>") !== -1) | ||
53 | } | 42 | } |
54 | 43 | ||
55 | function test_3htmlToPlainConversion() { | 44 | function test_3htmlToPlainConversion() { |
56 | var editor = createTemporaryObject(editorComponent, testCase, {initialText: "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\"><html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">p, li { white-space: pre-wrap; }</style></head><body style=\" font-family:'Noto Sans'; font-size:9pt; font-weight:400; font-style:normal;\"><p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">test</p></body></html>", htmlEnabled: true}) | 45 | var editor = createTemporaryObject(editorComponent, testCase, {initialText: htmlText}) |
57 | editor.htmlEnabled = false | 46 | editor.clearFormatting() |
58 | compare(editor.text, "test") | 47 | compare(editor.text, plainText) |
59 | |||
60 | editor.htmlEnabled = true | ||
61 | verify(editor.text.indexOf("<html>") !== -1) | ||
62 | } | 48 | } |
63 | 49 | ||
64 | function test_4detectPlain() { | 50 | function test_4detectPlain() { |
65 | var editor = createTemporaryObject(editorComponent, testCase, {initialText: "Foobar\nBarBar", htmlEnabled: true}) | 51 | var editor = createTemporaryObject(editorComponent, testCase, {initialText: plainText}) |
66 | compare(editor.htmlEnabled, false) | 52 | compare(editor.htmlEnabled, false) |
67 | } | 53 | } |
68 | 54 | ||
69 | function test_5detectHtml() { | 55 | function test_5detectHtml() { |
70 | var editor = createTemporaryObject(editorComponent, testCase, {initialText: "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\"><html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">p, li { white-space: pre-wrap; }</style></head><body style=\" font-family:'Noto Sans'; font-size:9pt; font-weight:400; font-style:normal;\"><p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">test</p></body></html>", htmlEnabled: false}) | 56 | var editor = createTemporaryObject(editorComponent, testCase, {initialText: htmlText}) |
71 | compare(editor.htmlEnabled, true) | 57 | compare(editor.htmlEnabled, true) |
72 | } | 58 | } |
73 | } | 59 | } |