Kaynağa Gözat

Small changes in selector

Kandrashin Denis 12 yıl önce
ebeveyn
işleme
00c1ce85bf

+ 5 - 6
source/fb2text.cpp

@@ -289,14 +289,13 @@ void FbTextPage::insertDate()
 
 void FbTextPage::createDiv(const QString &className)
 {
-    // $(document).children("html").children("body").children("div.body").children("div.section").get(0)
     QString style = className;
     QString js1 = jScript("section_get.js");
     QString result = mainFrame()->evaluateJavaScript(js1).toString();
-    int pos = result.indexOf("|");
-    if (pos == 0) return;
-    const QString location = result.left(pos);
-    const QString position = result.mid(pos + 1);
+    QStringList list = result.split("|");
+    if (list.count() < 2) return;
+    const QString location = list[0];
+    const QString position = list[1];
     if (style == "title" && position.left(2) != "0,") style.prepend("sub");
     FbTextElement original = element(location);
     FbTextElement duplicate = original.clone();
@@ -305,7 +304,7 @@ void FbTextPage::createDiv(const QString &className)
     QString js2 = jScript("section_new.js") + ";f(this,'%1',%2)";
     duplicate.evaluateJavaScript(js2.arg(style).arg(position));
     QUndoCommand * command = new FbReplaceCmd(original, duplicate);
-    push(command, tr("Create section"));
+    push(command, tr("Create <%1>").arg(className));
 }
 
 void FbTextPage::createSection()

+ 0 - 1
source/js/get_status.js

@@ -1,4 +1,3 @@
-logger.trace(locator(document.getSelection().baseNode));
 var baseNode = document.getSelection().baseNode;
 if (baseNode === null) ''; else {
 	(f = function(node){

+ 1 - 1
source/js/location.js

@@ -22,5 +22,5 @@ return (f = function(node){
 	} else {
         return prefix + ".children()" + ".eq(" + parent.children().index(node) + ")";
 	}
-})(node) + ".first()";
+})(node) + ".get(0)";
 };

+ 2 - 0
source/js/section_get.js

@@ -26,6 +26,8 @@ while(end.parentNode!==root) {
 return location(root)
 +"|"+$(root).children().index(start)
 +","+$(root).children().index(end)
++"|"+locator(range.startContainer)
 +","+range.startOffset
++","+locator(range.endContainer)
 +","+range.endOffset;
 })()

+ 1 - 0
source/js/section_new.js

@@ -7,6 +7,7 @@ range.setEndAfter(end);
 var newNode=document.createElement("div");
 newNode.className=style;
 range.surroundContents(newNode);
+range.setStartBefore(start);
 range.setEndBefore(start);
 var selection=window.getSelection();
 selection.removeAllRanges();