small improvements to text preview in file notes

This commit is contained in:
zadam 2020-08-04 22:06:25 +02:00
parent 8561201abc
commit 224fbdc8cd
3 changed files with 9 additions and 4 deletions

View File

@ -121,7 +121,7 @@ export default class FileTypeWidget extends TypeWidget {
this.$pdfPreview.attr('src', '').empty().hide(); this.$pdfPreview.attr('src', '').empty().hide();
if (noteComplement.content) { if (noteComplement.content) {
this.$previewContent.show(); this.$previewContent.show().scrollTop(0);
this.$previewContent.text(noteComplement.content); this.$previewContent.text(noteComplement.content);
} }
else if (note.mime === 'application/pdf' && utils.isElectron()) { else if (note.mime === 'application/pdf' && utils.isElectron()) {

View File

@ -17,8 +17,9 @@ async function getNote(req) {
if (note.isStringNote()) { if (note.isStringNote()) {
note.content = await note.getContent(); note.content = await note.getContent();
if (note.type === 'file') { if (note.type === 'file' && note.content.length > 10000) {
note.content = note.content.substr(0, 10000); note.content = note.content.substr(0, 10000)
+ `\r\n\r\n... and ${note.content.length - 10000} more characters.`;
} }
} }

View File

@ -159,7 +159,11 @@ function getContentDisposition(filename) {
return `file; filename="${sanitizedFilename}"; filename*=UTF-8''${sanitizedFilename}`; return `file; filename="${sanitizedFilename}"; filename*=UTF-8''${sanitizedFilename}`;
} }
const STRING_MIME_TYPES = ["application/x-javascript", "image/svg+xml"]; const STRING_MIME_TYPES = [
"application/javascript",
"application/x-javascript",
"image/svg+xml"
];
function isStringNote(type, mime) { function isStringNote(type, mime) {
return ["text", "code", "relation-map", "search"].includes(type) return ["text", "code", "relation-map", "search"].includes(type)