Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/lintest/fb2edit.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKandrashin Denis <mail@lintest.ru>2013-06-14 01:26:53 +0400
committerKandrashin Denis <mail@lintest.ru>2013-06-14 01:26:53 +0400
commiteb0c07c28ad9ddb545c3ea1ced5895095e371218 (patch)
tree61a4e737083cf2bdf249517f5f79fd9ecb9324d7
parent79dd943161e7ca2b26e8468cd3cb26ef55f9aa38 (diff)
Fix XML text selection
-rw-r--r--source/fb2save.cpp5
-rw-r--r--source/fb2save.hpp5
-rw-r--r--source/js/export.js2
3 files changed, 8 insertions, 4 deletions
diff --git a/source/fb2save.cpp b/source/fb2save.cpp
index 609cfd6..99006cd 100644
--- a/source/fb2save.cpp
+++ b/source/fb2save.cpp
@@ -119,6 +119,7 @@ void FbHtmlHandler::onNew(const QString &name)
void FbHtmlHandler::onTxt(const QString &text)
{
+ m_lastTextLength = text.length();
characters(text);
}
@@ -534,12 +535,12 @@ bool FbSaveHandler::comment(const QString& ch)
void FbSaveHandler::onAnchor(int offset)
{
- m_writer.setAnchor(offset);
+ m_writer.setAnchor(offset - m_lastTextLength);
}
void FbSaveHandler::onFocus(int offset)
{
- m_writer.setFocus(offset);
+ m_writer.setFocus(offset - m_lastTextLength);
}
FbXmlHandler::NodeHandler * FbSaveHandler::CreateRoot(const QString &name, const QXmlAttributes &atts)
diff --git a/source/fb2save.hpp b/source/fb2save.hpp
index 524f7ee..f0a1f0b 100644
--- a/source/fb2save.hpp
+++ b/source/fb2save.hpp
@@ -47,7 +47,7 @@ class FbHtmlHandler : public FbXmlHandler
Q_OBJECT
public:
- explicit FbHtmlHandler() {}
+ explicit FbHtmlHandler(): m_lastTextLength(0) {}
public slots:
void onAttr(const QString &name, const QString &value);
@@ -56,6 +56,9 @@ public slots:
void onTxt(const QString &text);
void onCom(const QString &text);
+protected:
+ int m_lastTextLength;
+
private:
static QString local(const QString &name);
diff --git a/source/js/export.js b/source/js/export.js
index 33e95e8..f02afdf 100644
--- a/source/js/export.js
+++ b/source/js/export.js
@@ -4,9 +4,9 @@
var focusNode = selection.focusNode;
var f = function(node) {
if (node.nodeName === "#text") {
+ handler.onTxt(node.data);
if (anchorNode === node) handler.onAnchor(selection.anchorOffset);
if (focusNode === node) handler.onFocus(selection.focusOffset);
- handler.onTxt(node.data);
} else if (node.nodeName === "#comment") {
handler.onCom(node.data);
} else {