Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
W
wax-prosemirror
Manage
Activity
Members
Labels
Plan
Issues
34
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
2
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Container Registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
wax
wax-prosemirror
Merge requests
!541
Image track
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Image track
image-track
into
master
Overview
0
Commits
4
Pipelines
0
Changes
8
Merged
Christos
requested to merge
image-track
into
master
1 year ago
Overview
0
Commits
4
Pipelines
0
Changes
1
Expand
0
0
Merge request reports
Viewing commit
6c73dc11
Prev
Next
Show latest version
1 file
+
17
−
4
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
6c73dc11
track image in between text
· 6c73dc11
chris
authored
1 year ago
wax-prosemirror-services/src/ImageService/fileUpload.js
+
17
−
4
Options
import
{
v4
as
uuidv4
}
from
'
uuid
'
;
import
{
Commands
}
from
'
wax-prosemirror-core
'
;
const
findPlaceholder
=
(
state
,
id
,
placeholderPlugin
)
=>
{
const
decos
=
placeholderPlugin
.
getState
(
state
);
@@ -7,12 +8,23 @@ const findPlaceholder = (state, id, placeholderPlugin) => {
};
export
default
(
view
,
fileUpload
,
placeholderPlugin
,
context
)
=>
file
=>
{
const
{
state
}
=
view
;
// const { state } = view;
const
trackChange
=
context
.
app
.
config
.
get
(
'
config.EnableTrackChangeService
'
);
if
(
trackChange
?.
enabled
)
if
(
context
.
pmViews
.
main
.
state
.
doc
.
resolve
(
context
.
pmViews
.
main
.
state
.
tr
.
selection
.
from
,
).
parent
.
nodeSize
!==
2
)
{
Commands
.
simulateKey
(
context
.
pmViews
.
main
,
13
,
'
Enter
'
);
}
// A fresh object to act as the ID for this upload
const
id
=
{};
// Replace the selection with a placeholder
const
{
tr
}
=
state
;
const
{
tr
}
=
context
.
pmViews
.
main
.
state
;
if
(
!
tr
.
selection
.
empty
)
tr
.
deleteSelection
();
tr
.
setMeta
(
placeholderPlugin
,
{
@@ -36,14 +48,15 @@ export default (view, fileUpload, placeholderPlugin, context) => file => {
if
(
pos
==
null
)
{
return
;
}
// Otherwise, insert it at the placeholder's position, and remove
// the placeholder
// if paragraph is empty don't break into new line
if
(
context
.
pmViews
.
main
.
state
.
doc
.
resolve
(
pos
).
parent
.
nodeSize
===
2
)
{
pos
-=
1
;
}
// Otherwise, insert it at the placeholder's position, and remove
// the placeholder
context
.
setOption
({
uploading
:
false
});
context
.
pmViews
.
main
.
dispatch
(
context
.
pmViews
.
main
.
state
.
tr