Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
SuperMan
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
1
Issues
1
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
罗超
SuperMan
Commits
3056d5c1
Commit
3056d5c1
authored
Aug 30, 2023
by
黄奎
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
页面修改
parent
207aaf55
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
36 additions
and
1 deletion
+36
-1
VEditDiv.vue
...wTravelmanager/TravelGroupControl/TravelTemp/VEditDiv.vue
+36
-1
No files found.
src/components/newTravelmanager/TravelGroupControl/TravelTemp/VEditDiv.vue
View file @
3056d5c1
...
...
@@ -21,6 +21,7 @@
},
methods
:
{
changeText
:
function
()
{
var
that
=
this
;
let
sel
=
window
.
getSelection
();
let
offset
=
sel
.
anchorOffset
;
if
(
this
.
textLength
&&
this
.
$el
.
innerText
.
length
>
this
.
textLength
)
{
...
...
@@ -32,16 +33,50 @@
var
range
=
sel
.
getRangeAt
(
0
);
var
textNode
=
range
.
startContainer
;
var
textNodeName
=
textNode
.
nodeName
;
console
.
log
(
"textNode"
,
textNode
.
nodeName
);
if
(
textNodeName
==
"#text"
)
{
range
.
setStart
(
textNode
,
offset
);
sel
.
removeAllRanges
();
sel
.
addRange
(
range
);
}
else
{
that
.
setCaretPosition
(
that
.
$el
,
offset
);
}
}
catch
(
err
)
{
console
.
log
(
err
);
}
},
0
);
},
//重置div光标位置
setCaretPosition
(
element
,
offset
)
{
var
range
=
document
.
createRange
();
var
sel
=
window
.
getSelection
();
//select appropriate node
var
currentNode
=
null
;
var
previousNode
=
null
;
for
(
var
i
=
0
;
i
<
element
.
childNodes
.
length
;
i
++
)
{
//save previous node
previousNode
=
currentNode
;
//get current node
currentNode
=
element
.
childNodes
[
i
];
//if we get span or something else then we should get child node
while
(
currentNode
.
childNodes
.
length
>
0
)
{
currentNode
=
currentNode
.
childNodes
[
0
];
}
//calc offset in current node
if
(
previousNode
!=
null
)
{
offset
-=
previousNode
.
length
;
}
//check whether current node has enough length
if
(
offset
<=
currentNode
.
length
)
{
break
;
}
}
//move caret to specified offset
if
(
currentNode
!=
null
)
{
range
.
setStart
(
currentNode
,
offset
);
range
.
collapse
(
true
);
sel
.
removeAllRanges
();
sel
.
addRange
(
range
);
}
}
}
};
...
...
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