Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
coopwire-hypothesis
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
孙灵跃 Leon Sun
coopwire-hypothesis
Commits
b3056d27
Commit
b3056d27
authored
Oct 19, 2016
by
Sean Roberts
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fallback to last text node when we will fall into a null sibling node situation fixes #122
parent
8e200e68
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
43 additions
and
2 deletions
+43
-2
pdf.coffee
h/static/scripts/annotator/anchoring/pdf.coffee
+1
-0
pdf-test.js
h/static/scripts/annotator/anchoring/test/pdf-test.js
+40
-0
annotator.js
h/static/scripts/vendor/annotator.js
+2
-2
No files found.
h/static/scripts/annotator/anchoring/pdf.coffee
View file @
b3056d27
...
...
@@ -244,6 +244,7 @@ exports.anchor = (root, selectors, options = {}) ->
exports
.
describe
=
(
root
,
range
,
options
=
{})
->
range
=
new
xpathRange
.
BrowserRange
(
range
).
normalize
()
startTextLayer
=
getNodeTextLayer
(
range
.
start
)
...
...
h/static/scripts/annotator/anchoring/test/pdf-test.js
View file @
b3056d27
...
...
@@ -29,6 +29,9 @@ var fixtures = {
'"My dear Mr. Bennet," said his lady to him one day, "have you heard that
\
n'
+
'Netherfield Park is occupied again?" '
,
'NODE A
\
nNODE B
\
nNODE C'
,
],
};
...
...
@@ -95,6 +98,42 @@ describe('PDF anchoring', function () {
});
});
});
it
(
'returns selector when range starts at end of text node with no next siblings'
,
function
()
{
// this problem is referenced in client issue #122
// But what is happening is the startContainer is referencing a text
// elment inside of a node. The logic in pdf#describe() was assuming if the
// selection was not middle of the word, the text node would have a nextSibling.
// However, if the selection is at the end of the only text node of its
// parent set, this fails.
viewer
.
setCurrentPage
(
3
);
var
quote
=
'NODE B'
;
// this selects NODE A text node
var
textNodeSelected
=
container
.
querySelector
(
'.textLayer div'
).
firstChild
;
var
staticRange
=
findText
(
container
,
quote
);
var
range
=
{
// put the selection at the very end of the node
startOffset
:
textNodeSelected
.
length
,
startContainer
:
textNodeSelected
,
endOffset
:
staticRange
.
endOffset
,
endContainer
:
staticRange
.
endContainer
,
commonAncestorContainer
:
staticRange
.
commonAncestorContainer
,
};
var
contentStr
=
fixtures
.
pdfContent
.
join
(
''
);
var
expectedPos
=
contentStr
.
replace
(
/
\n
/g
,
''
).
lastIndexOf
(
quote
);
return
pdfAnchoring
.
describe
(
container
,
range
).
then
(
function
(
selectors
)
{
var
position
=
selectors
[
0
];
assert
.
equal
(
position
.
start
,
expectedPos
);
assert
.
equal
(
position
.
end
,
expectedPos
+
quote
.
length
);
});
});
});
describe
(
'#anchor'
,
function
()
{
...
...
@@ -139,4 +178,5 @@ describe('PDF anchoring', function () {
});
});
});
});
h/static/scripts/vendor/annotator.js
View file @
b3056d27
...
...
@@ -622,7 +622,7 @@
}
nr
=
{};
if
(
r
.
startOffset
>
0
)
{
if
(
r
.
start
.
nodeValue
.
length
>
r
.
startOffset
)
{
if
(
!
r
.
start
.
nextSibling
||
r
.
start
.
nodeValue
.
length
>
r
.
startOffset
)
{
nr
.
start
=
r
.
start
.
splitText
(
r
.
startOffset
);
}
else
{
nr
.
start
=
r
.
start
.
nextSibling
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment