mirror of
https://github.com/pulsar-edit/pulsar.git
synced 2024-11-11 04:48:44 +03:00
Remove CompositeCursor and Selection. Move their remaining methods into Editor
This commit is contained in:
parent
31135afd9a
commit
cffadcf4a8
@ -873,7 +873,6 @@ describe "Editor", ->
|
||||
editor.setCursorScreenPosition [5, 5]
|
||||
|
||||
rootView.setFontSize(30)
|
||||
|
||||
expect(editor.css('font-size')).toBe '30px'
|
||||
expect(editor.lineHeight).toBeGreaterThan lineHeightBefore
|
||||
expect(editor.charWidth).toBeGreaterThan charWidthBefore
|
||||
|
@ -1,29 +0,0 @@
|
||||
CursorView = require 'cursor-view'
|
||||
_ = require 'underscore'
|
||||
|
||||
module.exports =
|
||||
class CompositeCursor
|
||||
constructor: (@editor) ->
|
||||
@cursors = []
|
||||
|
||||
getCursorView: (index) ->
|
||||
index ?= @cursors.length - 1
|
||||
@cursors[index]
|
||||
|
||||
getCursorViews: ->
|
||||
@cursors
|
||||
|
||||
addCursorView: (cursor) ->
|
||||
cursor = new CursorView(cursor, @editor)
|
||||
@cursors.push(cursor)
|
||||
@editor.renderedLines.append(cursor)
|
||||
cursor
|
||||
|
||||
removeCursorView: (cursorView) ->
|
||||
_.remove(@cursors, cursorView)
|
||||
|
||||
removeAllCursorViews: ->
|
||||
cursor.remove() for cursor in @getCursorViews()
|
||||
|
||||
updateAppearance: ->
|
||||
cursor.updateAppearance() for cursor in @cursors
|
@ -1,24 +0,0 @@
|
||||
SelectionView = require 'selection-view'
|
||||
_ = require 'underscore'
|
||||
|
||||
module.exports =
|
||||
class CompositeSeleciton
|
||||
constructor: (@editor) ->
|
||||
@selections = []
|
||||
|
||||
getSelectionView: (index) ->
|
||||
index ?= @selections.length - 1
|
||||
@selections[index]
|
||||
|
||||
addSelectionView: (selection) ->
|
||||
selection = new SelectionView({@editor, selection})
|
||||
@selections.push(selection)
|
||||
@editor.renderedLines.append(selection)
|
||||
selection
|
||||
|
||||
selectionViewForCursor: (cursor) ->
|
||||
for view in @selections
|
||||
return view if view.selection.cursor == cursor
|
||||
|
||||
removeSelectionView: (selectionView) ->
|
||||
_.remove(@selections, selectionView)
|
@ -27,7 +27,7 @@ class CursorView extends View
|
||||
@editor.syncCursorAnimations()
|
||||
|
||||
remove: ->
|
||||
@editor.compositeCursor.removeCursorView(this)
|
||||
@editor.removeCursorView(this)
|
||||
@cursor.off()
|
||||
super
|
||||
|
||||
|
@ -1,12 +1,12 @@
|
||||
{View, $$} = require 'space-pen'
|
||||
Buffer = require 'buffer'
|
||||
CompositeCursor = require 'composite-cursor'
|
||||
CompositeSelection = require 'composite-selection'
|
||||
Gutter = require 'gutter'
|
||||
Renderer = require 'renderer'
|
||||
Point = require 'point'
|
||||
Range = require 'range'
|
||||
EditSession = require 'edit-session'
|
||||
CursorView = require 'cursor-view'
|
||||
SelectionView = require 'selection-view'
|
||||
|
||||
$ = require 'jquery'
|
||||
_ = require 'underscore'
|
||||
@ -36,8 +36,8 @@ class Editor extends View
|
||||
lineHeight: null
|
||||
charWidth: null
|
||||
charHeight: null
|
||||
cursor: null
|
||||
selection: null
|
||||
cursorViews: null
|
||||
selectionViews: null
|
||||
buffer: null
|
||||
renderer: null
|
||||
autoIndent: null
|
||||
@ -64,8 +64,9 @@ class Editor extends View
|
||||
@lineCache = []
|
||||
@bindKeys()
|
||||
@autoIndent = true
|
||||
@buildCursorAndSelection()
|
||||
@handleEvents()
|
||||
@cursorViews = []
|
||||
@selectionViews = []
|
||||
@editSessions = []
|
||||
|
||||
if buffer?
|
||||
@ -144,10 +145,6 @@ class Editor extends View
|
||||
do (name, method) =>
|
||||
@on name, => method.call(this); false
|
||||
|
||||
buildCursorAndSelection: ->
|
||||
@compositeSelection = new CompositeSelection(this)
|
||||
@compositeCursor = new CompositeCursor(this)
|
||||
|
||||
addCursor: ->
|
||||
@activeEditSession.addCursorAtScreenPosition([0, 0])
|
||||
|
||||
@ -235,6 +232,32 @@ class Editor extends View
|
||||
@focus() if @isFocused
|
||||
@trigger 'editor-open', [this]
|
||||
|
||||
addCursorView: (cursor) ->
|
||||
cursorView = new CursorView(cursor, this)
|
||||
@cursorViews.push(cursorView)
|
||||
@renderedLines.append(cursorView)
|
||||
cursorView
|
||||
|
||||
removeCursorView: (cursorView) ->
|
||||
_.remove(@cursorViews, cursorView)
|
||||
|
||||
updateCursorViews: ->
|
||||
for cursorView in @getCursorViews()
|
||||
cursorView.updateAppearance()
|
||||
|
||||
addSelectionView: (selection) ->
|
||||
selectionView = new SelectionView({editor: this, selection})
|
||||
@selectionViews.push(selectionView)
|
||||
@renderedLines.append(selectionView)
|
||||
selectionView
|
||||
|
||||
selectionViewForCursor: (cursor) ->
|
||||
for selectionView in @selectionViews
|
||||
return selectionView if selectionView.selection.cursor == cursor
|
||||
|
||||
removeSelectionView: (selectionView) ->
|
||||
_.remove(@selectionViews, selectionView)
|
||||
|
||||
rootView: ->
|
||||
@parents('#root-view').view()
|
||||
|
||||
@ -374,16 +397,16 @@ class Editor extends View
|
||||
@activeEditSession.on 'screen-lines-change', (e) => @handleRendererChange(e)
|
||||
|
||||
for cursor in @activeEditSession.getCursors()
|
||||
@compositeCursor.addCursorView(cursor)
|
||||
@addCursorView(cursor)
|
||||
|
||||
for selection in @activeEditSession.getSelections()
|
||||
@compositeSelection.addSelectionView(selection)
|
||||
@addSelectionView(selection)
|
||||
|
||||
@activeEditSession.on 'add-cursor', (cursor) =>
|
||||
@compositeCursor.addCursorView(cursor)
|
||||
@addCursorView(cursor)
|
||||
|
||||
@activeEditSession.on 'add-selection', (selection) =>
|
||||
@compositeSelection.addSelectionView(selection)
|
||||
@addSelectionView(selection)
|
||||
|
||||
destroyEditSessions: ->
|
||||
session.destroy() for session in @editSessions
|
||||
@ -640,12 +663,19 @@ class Editor extends View
|
||||
if fontSize
|
||||
@css('font-size', fontSize + 'px')
|
||||
@calculateDimensions()
|
||||
@compositeCursor.updateAppearance()
|
||||
@updateCursorViews()
|
||||
@updateRenderedLines()
|
||||
|
||||
getCursorView: (index) -> @compositeCursor.getCursorView(index)
|
||||
getCursorViews: -> @compositeCursor.getCursorViews()
|
||||
removeAllCursorViews: -> @compositeCursor.removeAllCursorViews()
|
||||
getCursorView: (index) ->
|
||||
index ?= @cursorViews.length - 1
|
||||
@cursorViews[index]
|
||||
|
||||
getCursorViews: ->
|
||||
new Array(@cursorViews...)
|
||||
|
||||
removeAllCursorViews: ->
|
||||
cursorView.remove() for cursorView in @getCursorViews()
|
||||
|
||||
getCursor: (index) -> @activeEditSession.getCursor(index)
|
||||
getCursors: -> @activeEditSession.getCursors()
|
||||
getLastCursor: -> @activeEditSession.getLastCursor()
|
||||
@ -666,7 +696,10 @@ class Editor extends View
|
||||
setCursorBufferPosition: (position) -> @activeEditSession.setCursorBufferPosition(position)
|
||||
getCursorBufferPosition: -> @activeEditSession.getCursorBufferPosition()
|
||||
|
||||
getSelectionView: (index) -> @compositeSelection.getSelectionView(index)
|
||||
getSelectionView: (index) ->
|
||||
index ?= @selectionViews.length - 1
|
||||
@selectionViews[index]
|
||||
|
||||
getSelection: (index) -> @activeEditSession.getSelection(index)
|
||||
getSelections: -> @activeEditSession.getSelections()
|
||||
getSelectionsOrderedByBufferPosition: -> @activeEditSession.getSelectionsOrderedByBufferPosition()
|
||||
|
@ -55,5 +55,5 @@ class SelectionView extends View
|
||||
@selection.getScreenRange()
|
||||
|
||||
remove: (ignore) ->
|
||||
@editor.compositeSelection.removeSelectionView(this)
|
||||
@editor.removeSelectionView(this)
|
||||
super
|
||||
|
Loading…
Reference in New Issue
Block a user