diff --git a/src/trix/models/composition.coffee b/src/trix/models/composition.coffee index 7fdc53488..d07a58f5e 100644 --- a/src/trix/models/composition.coffee +++ b/src/trix/models/composition.coffee @@ -113,15 +113,17 @@ class Trix.Composition extends Trix.BasicObject @insertAttachment(attachment) insertFiles: (files) -> + attributes = @getCurrentTextAttributes() text = new Trix.Text for file in files when @delegate?.compositionShouldAcceptFile(file) attachment = Trix.Attachment.attachmentForFile(file) - attachmentText = Trix.Text.textForAttachmentWithAttributes(attachment, @currentAttributes) + attachmentText = Trix.Text.textForAttachmentWithAttributes(attachment, attributes) text = text.appendText(attachmentText) @insertText(text) insertAttachment: (attachment) -> - text = Trix.Text.textForAttachmentWithAttributes(attachment, @currentAttributes) + attributes = @getCurrentTextAttributes() + text = Trix.Text.textForAttachmentWithAttributes(attachment, attributes) @insertText(text) deleteInDirection: (direction) -> diff --git a/test/src/system/attachment_test.coffee b/test/src/system/attachment_test.coffee index a684cbdd3..1d3534ad4 100644 --- a/test/src/system/attachment_test.coffee +++ b/test/src/system/attachment_test.coffee @@ -1,4 +1,4 @@ -{after, assert, clickElement, defer, dragToCoordinates, moveCursor, pressKey, test, testGroup, triggerEvent, typeCharacters} = Trix.TestHelpers +{after, assert, clickElement, clickToolbarButton, createFile, defer, dragToCoordinates, moveCursor, pressKey, test, testGroup, triggerEvent, typeCharacters} = Trix.TestHelpers testGroup "Attachments", template: "editor_with_image", -> test "moving an image by drag and drop", (expectDocument) -> @@ -67,6 +67,24 @@ testGroup "Attachments", template: "editor_with_image", -> assert.locationRange index: 0, offset: 3 expectDocument "ab#{Trix.OBJECT_REPLACEMENT_CHARACTER}\n" + testGroup "File insertion", template: "editor_empty", -> + test "inserting a file in a formatted block", (expectDocument) -> + clickToolbarButton attribute: "bullet", -> + clickToolbarButton attribute: "bold", -> + getComposition().insertFile(createFile()) + assert.blockAttributes([0, 1], ["bulletList", "bullet"]) + assert.textAttributes([0, 1], bold: true) + expectDocument("#{Trix.OBJECT_REPLACEMENT_CHARACTER}\n") + + test "inserting a files in a formatted block", (expectDocument) -> + clickToolbarButton attribute: "quote", -> + clickToolbarButton attribute: "italic", -> + getComposition().insertFiles([createFile(), createFile()]) + assert.blockAttributes([0, 2], ["quote"]) + assert.textAttributes([0, 1], italic: true) + assert.textAttributes([1, 2], italic: true) + expectDocument("#{Trix.OBJECT_REPLACEMENT_CHARACTER}#{Trix.OBJECT_REPLACEMENT_CHARACTER}\n") + getFigure = -> findElement("figure")