|
|
@ -21,6 +21,8 @@ export default class ChatContextMenu { |
|
|
|
private isSelectable: boolean; |
|
|
|
private isSelectable: boolean; |
|
|
|
private target: HTMLElement; |
|
|
|
private target: HTMLElement; |
|
|
|
private isTargetAGroupedItem: boolean; |
|
|
|
private isTargetAGroupedItem: boolean; |
|
|
|
|
|
|
|
private isTextSelected: boolean; |
|
|
|
|
|
|
|
private isAnchorTarget: boolean; |
|
|
|
public peerId: number; |
|
|
|
public peerId: number; |
|
|
|
public mid: number; |
|
|
|
public mid: number; |
|
|
|
public message: any; |
|
|
|
public message: any; |
|
|
@ -66,6 +68,8 @@ export default class ChatContextMenu { |
|
|
|
this.peerId = this.chat.peerId; |
|
|
|
this.peerId = this.chat.peerId; |
|
|
|
//this.msgID = msgID;
|
|
|
|
//this.msgID = msgID;
|
|
|
|
this.target = e.target as HTMLElement; |
|
|
|
this.target = e.target as HTMLElement; |
|
|
|
|
|
|
|
this.isTextSelected = !isSelectionEmpty(); |
|
|
|
|
|
|
|
this.isAnchorTarget = this.target.tagName === 'A' && (this.target as HTMLAnchorElement).target === '_blank'; |
|
|
|
|
|
|
|
|
|
|
|
const groupedItem = findUpClassName(this.target, 'grouped-item'); |
|
|
|
const groupedItem = findUpClassName(this.target, 'grouped-item'); |
|
|
|
this.isTargetAGroupedItem = !!groupedItem; |
|
|
|
this.isTargetAGroupedItem = !!groupedItem; |
|
|
@ -188,12 +192,12 @@ export default class ChatContextMenu { |
|
|
|
icon: 'copy', |
|
|
|
icon: 'copy', |
|
|
|
text: 'Copy', |
|
|
|
text: 'Copy', |
|
|
|
onClick: this.onCopyClick, |
|
|
|
onClick: this.onCopyClick, |
|
|
|
verify: () => !!this.message.message && isSelectionEmpty() |
|
|
|
verify: () => !!this.message.message && !this.isTextSelected |
|
|
|
}, { |
|
|
|
}, { |
|
|
|
icon: 'copy', |
|
|
|
icon: 'copy', |
|
|
|
text: 'Copy Selected Text', |
|
|
|
text: 'Copy Selected Text', |
|
|
|
onClick: this.onCopyClick, |
|
|
|
onClick: this.onCopyClick, |
|
|
|
verify: () => !!this.message.message && !isSelectionEmpty() |
|
|
|
verify: () => !!this.message.message && this.isTextSelected |
|
|
|
}, { |
|
|
|
}, { |
|
|
|
icon: 'copy', |
|
|
|
icon: 'copy', |
|
|
|
text: 'Copy selected', |
|
|
|
text: 'Copy selected', |
|
|
@ -201,6 +205,12 @@ export default class ChatContextMenu { |
|
|
|
verify: () => this.chat.selection.selectedMids.has(this.mid) && !![...this.chat.selection.selectedMids].find(mid => !!this.chat.getMessage(mid).message), |
|
|
|
verify: () => this.chat.selection.selectedMids.has(this.mid) && !![...this.chat.selection.selectedMids].find(mid => !!this.chat.getMessage(mid).message), |
|
|
|
notDirect: () => true, |
|
|
|
notDirect: () => true, |
|
|
|
withSelection: true |
|
|
|
withSelection: true |
|
|
|
|
|
|
|
}, { |
|
|
|
|
|
|
|
icon: 'copy', |
|
|
|
|
|
|
|
text: 'Copy Link', |
|
|
|
|
|
|
|
onClick: this.onCopyAnchorLinkClick, |
|
|
|
|
|
|
|
verify: () => this.isAnchorTarget, |
|
|
|
|
|
|
|
withSelection: true |
|
|
|
}, { |
|
|
|
}, { |
|
|
|
icon: 'link', |
|
|
|
icon: 'link', |
|
|
|
text: 'Copy Link', |
|
|
|
text: 'Copy Link', |
|
|
@ -302,20 +312,21 @@ export default class ChatContextMenu { |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
private onCopyClick = () => { |
|
|
|
private onCopyClick = () => { |
|
|
|
let str: string; |
|
|
|
if(isSelectionEmpty()) { |
|
|
|
const selection = window.getSelection(); |
|
|
|
|
|
|
|
if(isSelectionEmpty(selection)) { |
|
|
|
|
|
|
|
const mids = this.chat.selection.isSelecting ? [...this.chat.selection.selectedMids] : [this.mid]; |
|
|
|
const mids = this.chat.selection.isSelecting ? [...this.chat.selection.selectedMids] : [this.mid]; |
|
|
|
str = mids.reduce((acc, mid) => { |
|
|
|
const str = mids.reduce((acc, mid) => { |
|
|
|
const message = this.chat.getMessage(mid); |
|
|
|
const message = this.chat.getMessage(mid); |
|
|
|
return acc + (message?.message ? message.message + '\n' : ''); |
|
|
|
return acc + (message?.message ? message.message + '\n' : ''); |
|
|
|
}, '').trim(); |
|
|
|
}, '').trim(); |
|
|
|
|
|
|
|
copyTextToClipboard(str); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
str = selection.toString(); |
|
|
|
document.execCommand('copy'); |
|
|
|
//cancelSelection();
|
|
|
|
//cancelSelection();
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
}; |
|
|
|
copyTextToClipboard(str); |
|
|
|
|
|
|
|
|
|
|
|
private onCopyAnchorLinkClick = () => { |
|
|
|
|
|
|
|
copyTextToClipboard((this.target as HTMLAnchorElement).href); |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
private onCopyLinkClick = () => { |
|
|
|
private onCopyLinkClick = () => { |
|
|
|