-
Notifications
You must be signed in to change notification settings - Fork 268
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/JS-5752: Url preview logic #1065
Open
mhlv
wants to merge
5
commits into
main
Choose a base branch
from
feature/JS-5752-url-preview-logic
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -173,7 +173,11 @@ const ChatForm = observer(class ChatForm extends React.Component<Props, State> { | |
> | ||
{attachments.map(item => ( | ||
<SwiperSlide key={item.id}> | ||
<Attachment object={item} onRemove={this.onAttachmentRemove} /> | ||
<Attachment | ||
object={item} | ||
onRemove={this.onAttachmentRemove} | ||
bookmarkAsDefault={true} | ||
/> | ||
</SwiperSlide> | ||
))} | ||
</Swiper> | ||
|
@@ -450,51 +454,48 @@ const ChatForm = observer(class ChatForm extends React.Component<Props, State> { | |
onPaste (e: any) { | ||
e.preventDefault(); | ||
|
||
const { from } = this.range; | ||
const { from, to } = this.range; | ||
const cb = e.clipboardData || e.originalEvent.clipboardData; | ||
const text = U.Common.normalizeLineEndings(String(cb.getData('text/plain') || '')); | ||
const electron = U.Common.getElectron(); | ||
const list = U.Common.getDataTransferFiles((e.clipboardData || e.originalEvent.clipboardData).items).map((it: File) => this.getObjectFromFile(it)).filter(it => { | ||
return !electron.isDirectory(it.path); | ||
}); | ||
const value = U.Common.stringInsert(this.getTextValue(), text, from, to); | ||
|
||
let value = this.getTextValue(); | ||
let url = U.Common.matchUrl(text); | ||
let isLocal = false; | ||
let to = this.range.to; | ||
this.range = { from: to, to: to + text.length }; | ||
this.refEditable.setValue(value); | ||
this.refEditable.setRange(this.range); | ||
this.refEditable.placeholderCheck(); | ||
|
||
if (!url) { | ||
url = U.Common.matchLocalPath(text); | ||
isLocal = true; | ||
if (list.length) { | ||
this.addAttachments(list); | ||
}; | ||
|
||
if (url) { | ||
const param = isLocal ? `file://${url}` : url; | ||
|
||
if (from == to) { | ||
value = U.Common.stringInsert(value, url + ' ', from, from); | ||
to = from + url.length; | ||
}; | ||
this.checkUrls(); | ||
this.onInput(); | ||
}; | ||
|
||
this.marks = Mark.adjust(this.marks, from - 1, url.length + 1); | ||
this.marks.push({ type: I.MarkType.Link, range: { from, to }, param}); | ||
this.updateMarkup(value, to + 1, to + 1); | ||
this.addBookmark(param); | ||
} else { | ||
value = U.Common.stringInsert(value, text, from, to); | ||
|
||
to = to + text.length; | ||
this.range = { from: to, to }; | ||
this.refEditable.setValue(value); | ||
this.refEditable.setRange(this.range); | ||
this.refEditable.placeholderCheck(); | ||
checkUrls () { | ||
const text = this.getTextValue(); | ||
const urls = U.Common.getUrlsFromText(text); | ||
if (!urls.length) { | ||
return; | ||
}; | ||
|
||
if (list.length) { | ||
this.addAttachments(list); | ||
}; | ||
this.removeBookmarks(); | ||
|
||
this.onInput(); | ||
window.setTimeout(() => { | ||
for (const url of urls) { | ||
const { from, to, isLocal, value } = url; | ||
const param = isLocal ? `file://${value}` : value; | ||
|
||
this.marks = Mark.adjust(this.marks, from - 1, value.length + 1); | ||
this.marks.push({ type: I.MarkType.Link, range: { from, to }, param}); | ||
this.addBookmark(param, true); | ||
}; | ||
this.updateMarkup(text, this.range.to + 1, this.range.to + 1); | ||
}, 150); | ||
Comment on lines
+488
to
+498
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. setTimeout? Looks like workaround. |
||
}; | ||
|
||
canDrop (e: any): boolean { | ||
|
@@ -551,7 +552,7 @@ const ChatForm = observer(class ChatForm extends React.Component<Props, State> { | |
this.setState({ attachments: this.checkLimit('attachments', list) }, callBack); | ||
}; | ||
|
||
addBookmark (url: string) { | ||
addBookmark (url: string, fromText?: boolean) { | ||
const add = (param: any) => { | ||
const { title, description, url } = param; | ||
const item = { | ||
|
@@ -562,6 +563,7 @@ const ChatForm = observer(class ChatForm extends React.Component<Props, State> { | |
source: url, | ||
isTmp: true, | ||
timestamp: U.Date.now(), | ||
fromText | ||
}; | ||
this.addAttachments([ item ]); | ||
}; | ||
|
@@ -577,7 +579,7 @@ const ChatForm = observer(class ChatForm extends React.Component<Props, State> { | |
|
||
removeBookmarks () { | ||
const attachments = this.state.attachments || []; | ||
const bookmarks = attachments.filter(it => it.layout == I.ObjectLayout.Bookmark); | ||
const bookmarks = attachments.filter(it => (it.layout == I.ObjectLayout.Bookmark) && it.fromText); | ||
|
||
let filtered = attachments; | ||
bookmarks.forEach(it => { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do not understand how this should work
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i pass bookmarkAsDefault=true in case there are more than 1 attachment in the message and for all attachments in the message form