mirror of
https://github.com/atom/atom.git
synced 2026-04-28 03:01:47 -04:00
Statically assign a clipboard instance to the TextEditor class
This commit is contained in:
@@ -28,7 +28,6 @@ ThemeManager = require './theme-manager'
|
||||
MenuManager = require './menu-manager'
|
||||
ContextMenuManager = require './context-menu-manager'
|
||||
CommandInstaller = require './command-installer'
|
||||
Clipboard = require './clipboard'
|
||||
Project = require './project'
|
||||
TitleBar = require './title-bar'
|
||||
Workspace = require './workspace'
|
||||
@@ -127,7 +126,7 @@ class AtomEnvironment extends Model
|
||||
|
||||
# Call .loadOrCreate instead
|
||||
constructor: (params={}) ->
|
||||
{@blobStore, @applicationDelegate, @window, @document, @configDirPath, @enablePersistence, onlyLoadBaseStyleSheets} = params
|
||||
{@blobStore, @applicationDelegate, @window, @document, @clipboard, @configDirPath, @enablePersistence, onlyLoadBaseStyleSheets} = params
|
||||
|
||||
@unloaded = false
|
||||
@loadTime = null
|
||||
@@ -182,20 +181,18 @@ class AtomEnvironment extends Model
|
||||
@packages.setContextMenuManager(@contextMenu)
|
||||
@packages.setThemeManager(@themes)
|
||||
|
||||
@clipboard = new Clipboard()
|
||||
|
||||
@project = new Project({notificationManager: @notifications, packageManager: @packages, @config, @applicationDelegate})
|
||||
|
||||
@commandInstaller = new CommandInstaller(@getVersion(), @applicationDelegate)
|
||||
|
||||
@textEditors = new TextEditorRegistry({
|
||||
@config, grammarRegistry: @grammars, assert: @assert.bind(this), @clipboard,
|
||||
@config, grammarRegistry: @grammars, assert: @assert.bind(this),
|
||||
packageManager: @packages
|
||||
})
|
||||
|
||||
@workspace = new Workspace({
|
||||
@config, @project, packageManager: @packages, grammarRegistry: @grammars, deserializerManager: @deserializers,
|
||||
notificationManager: @notifications, @applicationDelegate, @clipboard, viewRegistry: @views, assert: @assert.bind(this),
|
||||
notificationManager: @notifications, @applicationDelegate, viewRegistry: @views, assert: @assert.bind(this),
|
||||
textEditorRegistry: @textEditors,
|
||||
})
|
||||
|
||||
|
||||
@@ -20,16 +20,21 @@ module.exports = ({blobStore}) ->
|
||||
|
||||
AtomEnvironment = require './atom-environment'
|
||||
ApplicationDelegate = require './application-delegate'
|
||||
Clipboard = require './clipboard'
|
||||
TextEditor = require './text-editor'
|
||||
|
||||
clipboard = new Clipboard
|
||||
TextEditor.setClipboard(clipboard)
|
||||
|
||||
window.atom = new AtomEnvironment({
|
||||
window, document, blobStore,
|
||||
window, document, clipboard, blobStore,
|
||||
applicationDelegate: new ApplicationDelegate,
|
||||
configDirPath: process.env.ATOM_HOME
|
||||
enablePersistence: true
|
||||
configDirPath: process.env.ATOM_HOME,
|
||||
enablePersistence: true,
|
||||
env: process.env
|
||||
})
|
||||
|
||||
atom.startEditorWindow().then ->
|
||||
|
||||
# Workaround for focus getting cleared upon window creation
|
||||
windowFocused = ->
|
||||
window.removeEventListener('focus', windowFocused)
|
||||
|
||||
@@ -21,6 +21,8 @@ module.exports = ({blobStore}) ->
|
||||
{getWindowLoadSettings} = require './window-load-settings-helpers'
|
||||
AtomEnvironment = require '../src/atom-environment'
|
||||
ApplicationDelegate = require '../src/application-delegate'
|
||||
Clipboard = require '../src/clipboard'
|
||||
TextEditor = require '../src/text-editor'
|
||||
require '../src/electron-shims'
|
||||
|
||||
{testRunnerPath, legacyTestRunnerPath, headless, logFile, testPaths} = getWindowLoadSettings()
|
||||
@@ -58,11 +60,15 @@ module.exports = ({blobStore}) ->
|
||||
|
||||
document.title = "Spec Suite"
|
||||
|
||||
clipboard = new Clipboard
|
||||
TextEditor.setClipboard(clipboard)
|
||||
|
||||
testRunner = require(testRunnerPath)
|
||||
legacyTestRunner = require(legacyTestRunnerPath)
|
||||
buildDefaultApplicationDelegate = -> new ApplicationDelegate()
|
||||
buildAtomEnvironment = (params) ->
|
||||
params = cloneObject(params)
|
||||
params.clipboard = clipboard unless params.hasOwnProperty("clipboard")
|
||||
params.blobStore = blobStore unless params.hasOwnProperty("blobStore")
|
||||
params.onlyLoadBaseStyleSheets = true unless params.hasOwnProperty("onlyLoadBaseStyleSheets")
|
||||
new AtomEnvironment(params)
|
||||
|
||||
@@ -14,7 +14,7 @@ class Selection extends Model
|
||||
initialScreenRange: null
|
||||
wordwise: false
|
||||
|
||||
constructor: ({@cursor, @marker, @editor, id, @clipboard}) ->
|
||||
constructor: ({@cursor, @marker, @editor, id}) ->
|
||||
@emitter = new Emitter
|
||||
|
||||
@assignId(id)
|
||||
@@ -605,7 +605,7 @@ class Selection extends Model
|
||||
startLevel = @editor.indentLevelForLine(precedingText)
|
||||
|
||||
if maintainClipboard
|
||||
{text: clipboardText, metadata} = @clipboard.readWithMetadata()
|
||||
{text: clipboardText, metadata} = @editor.constructor.clipboard.readWithMetadata()
|
||||
metadata ?= {}
|
||||
unless metadata.selections?
|
||||
metadata.selections = [{
|
||||
@@ -618,9 +618,9 @@ class Selection extends Model
|
||||
indentBasis: startLevel,
|
||||
fullLine: fullLine
|
||||
})
|
||||
@clipboard.write([clipboardText, selectionText].join("\n"), metadata)
|
||||
@editor.constructor.clipboard.write([clipboardText, selectionText].join("\n"), metadata)
|
||||
else
|
||||
@clipboard.write(selectionText, {
|
||||
@editor.constructor.clipboard.write(selectionText, {
|
||||
indentBasis: startLevel,
|
||||
fullLine: fullLine
|
||||
})
|
||||
|
||||
@@ -39,9 +39,8 @@ const GRAMMAR_SELECTION_RANGE = Range(Point.ZERO, Point(10, 0)).freeze()
|
||||
// done using your editor, be sure to call `dispose` on the returned disposable
|
||||
// to avoid leaking editors.
|
||||
export default class TextEditorRegistry {
|
||||
constructor ({config, grammarRegistry, clipboard, assert, packageManager}) {
|
||||
constructor ({config, grammarRegistry, assert, packageManager}) {
|
||||
this.assert = assert
|
||||
this.clipboard = clipboard
|
||||
this.config = config
|
||||
this.grammarRegistry = grammarRegistry
|
||||
this.scopedSettingsDelegate = new ScopedSettingsDelegate(config)
|
||||
@@ -109,10 +108,7 @@ export default class TextEditorRegistry {
|
||||
}
|
||||
|
||||
build (params) {
|
||||
params = Object.assign({
|
||||
clipboard: this.clipboard,
|
||||
assert: this.assert
|
||||
}, params)
|
||||
params = Object.assign({assert: this.assert}, params)
|
||||
|
||||
let scope = null
|
||||
if (params.buffer) {
|
||||
|
||||
@@ -59,6 +59,9 @@ ZERO_WIDTH_NBSP = '\ufeff'
|
||||
# soft wraps and folds to ensure your code interacts with them correctly.
|
||||
module.exports =
|
||||
class TextEditor extends Model
|
||||
@setClipboard: (clipboard) ->
|
||||
@clipboard = clipboard
|
||||
|
||||
serializationVersion: 1
|
||||
|
||||
buffer: null
|
||||
@@ -114,7 +117,6 @@ class TextEditor extends Model
|
||||
if state.displayLayer = state.buffer.getDisplayLayer(state.displayLayerId)
|
||||
state.selectionsMarkerLayer = state.displayLayer.getMarkerLayer(state.selectionsMarkerLayerId)
|
||||
|
||||
state.clipboard = atomEnvironment.clipboard
|
||||
state.assert = atomEnvironment.assert.bind(atomEnvironment)
|
||||
editor = new this(state)
|
||||
if state.registered
|
||||
@@ -123,19 +125,20 @@ class TextEditor extends Model
|
||||
editor
|
||||
|
||||
constructor: (params={}) ->
|
||||
unless @constructor.clipboard?
|
||||
throw new Error("Must call TextEditor.setClipboard at least once before creating TextEditor instances")
|
||||
|
||||
super
|
||||
|
||||
{
|
||||
@softTabs, @firstVisibleScreenRow, @firstVisibleScreenColumn, initialLine, initialColumn, tabLength,
|
||||
@softWrapped, @decorationManager, @selectionsMarkerLayer, @buffer, suppressCursorCreation,
|
||||
@mini, @placeholderText, lineNumberGutterVisible, @largeFileMode, @clipboard,
|
||||
@mini, @placeholderText, lineNumberGutterVisible, @largeFileMode,
|
||||
@assert, grammar, @showInvisibles, @autoHeight, @autoWidth, @scrollPastEnd, @editorWidthInChars,
|
||||
@tokenizedBuffer, @displayLayer, @invisibles, @showIndentGuide,
|
||||
@softWrapped, @softWrapAtPreferredLineLength, @preferredLineLength
|
||||
} = params
|
||||
|
||||
throw new Error("Must pass a clipboard parameter when constructing TextEditors") unless @clipboard?
|
||||
|
||||
@assert ?= (condition) -> condition
|
||||
@firstVisibleScreenRow ?= 0
|
||||
@firstVisibleScreenColumn ?= 0
|
||||
@@ -705,7 +708,7 @@ class TextEditor extends Model
|
||||
suppressCursorCreation: true,
|
||||
tabLength: @tokenizedBuffer.getTabLength(),
|
||||
@firstVisibleScreenRow, @firstVisibleScreenColumn,
|
||||
@clipboard, @assert, displayLayer, grammar: @getGrammar(),
|
||||
@assert, displayLayer, grammar: @getGrammar(),
|
||||
@autoWidth, @autoHeight
|
||||
})
|
||||
|
||||
@@ -2718,7 +2721,7 @@ class TextEditor extends Model
|
||||
# Returns the new {Selection}.
|
||||
addSelection: (marker, options={}) ->
|
||||
cursor = @addCursor(marker)
|
||||
selection = new Selection(Object.assign({editor: this, marker, cursor, @clipboard}, options))
|
||||
selection = new Selection(Object.assign({editor: this, marker, cursor}, options))
|
||||
@selections.push(selection)
|
||||
selectionBufferRange = selection.getBufferRange()
|
||||
@mergeIntersectingSelections(preserveFolds: options.preserveFolds)
|
||||
@@ -3127,7 +3130,7 @@ class TextEditor extends Model
|
||||
#
|
||||
# * `options` (optional) See {Selection::insertText}.
|
||||
pasteText: (options={}) ->
|
||||
{text: clipboardText, metadata} = @clipboard.readWithMetadata()
|
||||
{text: clipboardText, metadata} = @constructor.clipboard.readWithMetadata()
|
||||
return false unless @emitWillInsertTextEvent(clipboardText)
|
||||
|
||||
metadata ?= {}
|
||||
|
||||
@@ -28,7 +28,7 @@ class Workspace extends Model
|
||||
|
||||
{
|
||||
@packageManager, @config, @project, @grammarRegistry, @notificationManager,
|
||||
@clipboard, @viewRegistry, @grammarRegistry, @applicationDelegate, @assert,
|
||||
@viewRegistry, @grammarRegistry, @applicationDelegate, @assert,
|
||||
@deserializerManager, @textEditorRegistry
|
||||
} = params
|
||||
|
||||
|
||||
Reference in New Issue
Block a user