Skip to content

Commit

Permalink
fix(context): Copy Cell via Context Menu shouldn't include Tree symbols
Browse files Browse the repository at this point in the history
- since the Context Menu Copy Cell command uses Export Formatter (when defined), it was including extra Tree/Grouping symbols that we don't want to see when doing a Copy Cell, so we should strip these symbols from the start of a string only.
  • Loading branch information
ghiscoding committed Sep 28, 2021
1 parent 42df051 commit f710084
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion packages/common/src/extensions/contextMenuExtension.ts
Expand Up @@ -424,13 +424,16 @@ export class ContextMenuExtension implements Extension {
textToCopy = this.getCellValueFromQueryFieldGetter(columnDef, dataContext);
}

// remove any unwanted Tree Data/Grouping symbols from the beginning of the string before copying (e.g.: "⮟ Task 21" or "· Task 2")
const finalTextToCopy = textToCopy.replace(/^([·|⮞|⮟]\s*)|([·|⮞|⮟])\s*/g, '');

// create fake <textarea> (positioned outside of the screen) to copy into clipboard & delete it from the DOM once we're done
const tmpElem = document.createElement('textarea') as HTMLTextAreaElement;
if (tmpElem && document.body) {
tmpElem.style.position = 'absolute';
tmpElem.style.left = '-1000px';
tmpElem.style.top = '-1000px';
tmpElem.value = textToCopy;
tmpElem.value = finalTextToCopy;
document.body.appendChild(tmpElem);
tmpElem.select();
const success = document.execCommand('copy', false, textToCopy);
Expand Down

0 comments on commit f710084

Please sign in to comment.