fix #743: copying entry fields to clipboard

This commit is contained in:
antelle 2019-09-14 17:06:38 +02:00
parent 56d84e1d18
commit b06cb26edc
7 changed files with 56 additions and 12 deletions

View File

@ -48,6 +48,23 @@ const CopyPaste = {
hiddenInput.remove();
}
});
},
copyHtml(html) {
const el = document.createElement('div');
el.innerHTML = html;
document.body.appendChild(el);
const range = document.createRange();
range.selectNodeContents(el);
const sel = window.getSelection();
sel.removeAllRanges();
sel.addRange(range);
const result = document.execCommand('copy');
el.remove();
return result;
}
};

View File

@ -105,6 +105,10 @@ const KdbxToHtml = {
appVersion: RuntimeInfo.version,
content
});
},
entryToHtml(db, entry) {
return walkEntry(db, entry, []);
}
};

View File

@ -273,6 +273,7 @@
"detMenuCopyUser": "Copy user",
"detSetupOtp": "One-time passwords",
"detClone": "Make a copy",
"detCopyEntryToClipboard": "Copy values to clipboard",
"detClonedName": "Copy",
"detAutoType": "Auto-type",
"detAutoTypeSettings": "Auto-type settings",

View File

@ -6,6 +6,7 @@ const IconUrl = require('../util/icon-url');
const Otp = require('../util/otp');
const kdbxweb = require('kdbxweb');
const Ranking = require('../util/ranking');
const KdbxToHtml = require('../comp/kdbx-to-html');
const EntryModel = Backbone.Model.extend({
defaults: {},
@ -704,6 +705,10 @@ const EntryModel = Backbone.Model.extend({
const fieldWeight = fieldWeights[fieldName] || defaultFieldWeight;
return rank + stringRank * fieldWeight;
}, 0);
},
getHtml() {
return KdbxToHtml.entryToHtml(this.file.db, this.entry);
}
});

View File

@ -453,6 +453,11 @@ const DetailsView = Backbone.View.extend({
});
}
moreOptions.push({ value: 'clone', icon: 'clone', text: Locale.detClone });
moreOptions.push({
value: 'copy-to-clipboard',
icon: 'copy',
text: Locale.detCopyEntryToClipboard
});
const rect = this.moreView.labelEl[0].getBoundingClientRect();
dropdownView.render({
position: { top: rect.bottom, left: rect.left },
@ -485,6 +490,9 @@ const DetailsView = Backbone.View.extend({
case 'clone':
this.clone();
break;
case 'copy-to-clipboard':
this.copyToClipboard();
break;
default:
if (e.item.lastIndexOf('add:', 0) === 0) {
const fieldName = e.item.substr(4);
@ -967,6 +975,10 @@ const DetailsView = Backbone.View.extend({
Backbone.trigger('select-entry', newEntry);
},
copyToClipboard() {
CopyPaste.copyHtml(this.model.getHtml());
},
deleteFromTrash() {
Alerts.yesno({
header: Locale.detDelFromTrash,

View File

@ -20,21 +20,25 @@
<td>{{tags}}</td>
</tr>
{{/if}}
<tr>
<td>{{Res 'group'}}</td>
<td>{{path}}</td>
</tr>
{{#if attachments.length}}
{{#if path}}
<tr>
<td>{{res 'detAttachments'}}</td>
<td>
{{#each attachments as |attachment|}}
<a href="{{{attachment.data}}}" download="{{attachment.name}}">{{attachment.name}}</a>
{{~#unless @last}},&nbsp;{{/unless}}
{{/each}}
</td>
<td>{{Res 'group'}}</td>
<td>{{path}}</td>
</tr>
{{/if}}
{{#if attachments}}
{{#if attachments.length}}
<tr>
<td>{{res 'detAttachments'}}</td>
<td>
{{#each attachments as |attachment|}}
<a href="{{{attachment.data}}}" download="{{attachment.name}}">{{attachment.name}}</a>
{{~#unless @last}},&nbsp;{{/unless}}
{{/each}}
</td>
</tr>
{{/if}}
{{/if}}
<tr>
<td>{{res 'detCreated'}}</td>
<td>{{created}}</td>

View File

@ -7,6 +7,7 @@ Release notes
`+` #1255: file format version and kdf selection in settings
`*` #502: increased the default value of encryption rounds
`+` #348: configurable system-wide shortcuts
`+` #743: copying entry fields to clipboard
`*` devtools are now opened with alt-cmd-I
`-` fix #764: multiple attachments display
`-` fix multi-line fields display in history