mirror of
https://github.com/Foundry376/Mailspring.git
synced 2024-12-29 03:43:16 +08:00
1e8fd46342
Summary: This diff contains a few major changes: 1. Scribe is no longer used for the text editor. It's just a plain contenteditable region. The toolbar items (bold, italic, underline) still work. Scribe was causing React inconcistency issues in the following scenario: - View thread with draft, edit draft - Move to another thread - Move back to thread with draft - Move to another thread. Notice that one or more messages from thread with draft are still there. There may be a way to fix this, but I tried for hours and there are Github Issues open on it's repository asking for React compatibility, so it may be fixed soon. For now contenteditable is working great. 2. Action.saveDraft() is no longer debounced in the DraftStore. Instead, firing that action causes the save to happen immediately, and the DraftStoreProxy has a new "DraftChangeSet" class which is responsbile for batching saves as the user interacts with the ComposerView. There are a couple big wins here: - In the future, we may want to be able to call Action.saveDraft() in other situations and it should behave like a normal action. We may also want to expose the DraftStoreProxy as an easy way of backing interactive draft UI. - Previously, when you added a contact to To/CC/BCC, this happened: <input> -> Action.saveDraft -> (delay!!) -> Database -> DraftStore -> DraftStoreProxy -> View Updates Increasing the delay to something reasonable like 200msec meant there was 200msec of lag before you saw the new view state. To fix this, I created a new class called DraftChangeSet which is responsible for accumulating changes as they're made and firing Action.saveDraft. "Adding" a change to the change set also causes the Draft provided by the DraftStoreProxy to change immediately (the changes are a temporary layer on top of the database object). This means no delay while changes are being applied. There's a better explanation in the source! This diff includes a few minor fixes as well: 1. Draft.state is gone—use Message.object = draft instead 2. String model attributes should never be null 3. Pre-send checks that can cancel draft send 4. Put the entire curl history and task queue into feedback reports 5. Cache localIds for extra speed 6. Move us up to latest React Test Plan: No new tests - once we lock down this new design I'll write tests for the DraftChangeSet Reviewers: evan Reviewed By: evan Differential Revision: https://review.inboxapp.com/D1125
107 lines
5 KiB
CoffeeScript
107 lines
5 KiB
CoffeeScript
path = require 'path'
|
|
fs = require 'fs-plus'
|
|
temp = require 'temp'
|
|
|
|
describe "the `syntax` global", ->
|
|
beforeEach ->
|
|
waitsForPromise ->
|
|
atom.packages.activatePackage('language-text')
|
|
|
|
waitsForPromise ->
|
|
atom.packages.activatePackage('language-javascript')
|
|
|
|
waitsForPromise ->
|
|
atom.packages.activatePackage('language-coffee-script')
|
|
|
|
waitsForPromise ->
|
|
atom.packages.activatePackage('language-ruby')
|
|
|
|
afterEach ->
|
|
atom.packages.deactivatePackages()
|
|
atom.packages.unloadPackages()
|
|
|
|
describe "serialization", ->
|
|
it "remembers grammar overrides by path", ->
|
|
filePath = '/foo/bar/file.js'
|
|
expect(atom.grammars.selectGrammar(filePath).name).not.toBe 'Ruby'
|
|
atom.grammars.setGrammarOverrideForPath(filePath, 'source.ruby')
|
|
syntax2 = atom.deserializers.deserialize(atom.grammars.serialize())
|
|
syntax2.addGrammar(grammar) for grammar in atom.grammars.grammars when grammar isnt atom.grammars.nullGrammar
|
|
expect(syntax2.selectGrammar(filePath).name).toBe 'Ruby'
|
|
|
|
describe ".selectGrammar(filePath)", ->
|
|
it "can use the filePath to load the correct grammar based on the grammar's filetype", ->
|
|
waitsForPromise ->
|
|
atom.packages.activatePackage('language-git')
|
|
|
|
runs ->
|
|
expect(atom.grammars.selectGrammar("file.js").name).toBe "JavaScript" # based on extension (.js)
|
|
expect(atom.grammars.selectGrammar(path.join(temp.dir, '.git', 'config')).name).toBe "Git Config" # based on end of the path (.git/config)
|
|
expect(atom.grammars.selectGrammar("Rakefile").name).toBe "Ruby" # based on the file's basename (Rakefile)
|
|
expect(atom.grammars.selectGrammar("curb").name).toBe "Null Grammar"
|
|
expect(atom.grammars.selectGrammar("/hu.git/config").name).toBe "Null Grammar"
|
|
|
|
it "uses the filePath's shebang line if the grammar cannot be determined by the extension or basename", ->
|
|
filePath = require.resolve("./fixtures/shebang")
|
|
expect(atom.grammars.selectGrammar(filePath).name).toBe "Ruby"
|
|
|
|
it "uses the number of newlines in the first line regex to determine the number of lines to test against", ->
|
|
waitsForPromise ->
|
|
atom.packages.activatePackage('language-property-list')
|
|
|
|
runs ->
|
|
fileContent = "first-line\n<html>"
|
|
expect(atom.grammars.selectGrammar("dummy.coffee", fileContent).name).toBe "CoffeeScript"
|
|
|
|
fileContent = '<?xml version="1.0" encoding="UTF-8"?>'
|
|
expect(atom.grammars.selectGrammar("grammar.tmLanguage", fileContent).name).toBe "Null Grammar"
|
|
|
|
fileContent += '\n<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">'
|
|
expect(atom.grammars.selectGrammar("grammar.tmLanguage", fileContent).name).toBe "Property List (XML)"
|
|
|
|
it "doesn't read the file when the file contents are specified", ->
|
|
filePath = require.resolve("./fixtures/shebang")
|
|
filePathContents = fs.readFileSync(filePath, 'utf8')
|
|
spyOn(fs, 'read').andCallThrough()
|
|
expect(atom.grammars.selectGrammar(filePath, filePathContents).name).toBe "Ruby"
|
|
expect(fs.read).not.toHaveBeenCalled()
|
|
|
|
it "allows the default grammar to be overridden for a path", ->
|
|
filePath = '/foo/bar/file.js'
|
|
expect(atom.grammars.selectGrammar(filePath).name).not.toBe 'Ruby'
|
|
atom.grammars.setGrammarOverrideForPath(filePath, 'source.ruby')
|
|
expect(atom.grammars.selectGrammar(filePath).name).toBe 'Ruby'
|
|
atom.grammars.clearGrammarOverrideForPath(filePath)
|
|
expect(atom.grammars.selectGrammar(filePath).name).not.toBe 'Ruby'
|
|
|
|
describe "when multiple grammars have matching fileTypes", ->
|
|
it "selects the grammar with the longest fileType match", ->
|
|
grammarPath1 = temp.path(suffix: '.json')
|
|
fs.writeFileSync grammarPath1, JSON.stringify(
|
|
name: 'test1'
|
|
scopeName: 'source1'
|
|
fileTypes: ['test']
|
|
)
|
|
grammar1 = atom.grammars.loadGrammarSync(grammarPath1)
|
|
expect(atom.grammars.selectGrammar('more.test', '')).toBe grammar1
|
|
|
|
grammarPath2 = temp.path(suffix: '.json')
|
|
fs.writeFileSync grammarPath2, JSON.stringify(
|
|
name: 'test2'
|
|
scopeName: 'source2'
|
|
fileTypes: ['test', 'more.test']
|
|
)
|
|
grammar2 = atom.grammars.loadGrammarSync(grammarPath2)
|
|
expect(atom.grammars.selectGrammar('more.test', '')).toBe grammar2
|
|
|
|
describe "when there is no file path", ->
|
|
it "does not throw an exception (regression)", ->
|
|
expect(-> atom.grammars.selectGrammar(null, '#!/usr/bin/ruby')).not.toThrow()
|
|
expect(-> atom.grammars.selectGrammar(null, '')).not.toThrow()
|
|
expect(-> atom.grammars.selectGrammar(null, null)).not.toThrow()
|
|
|
|
describe ".removeGrammar(grammar)", ->
|
|
it "removes the grammar, so it won't be returned by selectGrammar", ->
|
|
grammar = atom.grammars.selectGrammar('foo.js')
|
|
atom.grammars.removeGrammar(grammar)
|
|
expect(atom.grammars.selectGrammar('foo.js').name).not.toBe grammar.name
|