Skip to content
This repository has been archived by the owner on Mar 13, 2023. It is now read-only.

Commit

Permalink
Merge pull request #22 from atom/fix-editorview-editor-api
Browse files Browse the repository at this point in the history
Attempt to update editorview API to work again
  • Loading branch information
Coby Chapple committed Jan 17, 2014
2 parents bec0350 + 5862e62 commit c2bb218
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 32 deletions.
62 changes: 32 additions & 30 deletions lib/editor-proxy.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@ tabStops = emmet.require("tabStops")

module.exports =
setupContext: (@editorView) ->
@indentation = @editorView.editor.getTabText()
@indentation = @editorView.getEditor().getTabText()
emmet.require("resources").setVariable("indentation", @indentation)
@syntax = @getSyntax()

# Fetches the character indexes of the selected text.
#
# Returns an {Object} with `start` and `end` properties.
getSelectionRange: ->
range = @editorView.getSelection().getBufferRange()
range = @editorView.getEditor().getSelection().getBufferRange()
return {
start: @editorView.editor.getBuffer().characterIndexForPosition(range.start),
end: @editorView.editor.getBuffer().characterIndexForPosition(range.end)
start: @editorView.getEditor().getBuffer().characterIndexForPosition(range.start),
end: @editorView.getEditor().getBuffer().characterIndexForPosition(range.end)
}

# Creates a selection from the `start` to `end` character indexes.
Expand All @@ -26,38 +26,38 @@ module.exports =
# start - A {Number} representing the starting character index
# end - A {Number} representing the ending character index
createSelection: (start, end) ->
@editorView.getSelection().setBufferRange
start: @editorView.editor.getBuffer().positionForCharacterIndex(start)
end: @editorView.editor.getBuffer().positionForCharacterIndex(end)
@editorView.getEditor().getSelection().setBufferRange
start: @editorView.getEditor().getBuffer().positionForCharacterIndex(start)
end: @editorView.getEditor().getBuffer().positionForCharacterIndex(end)

# Fetches the current line's start and end indexes.
#
# Returns an {Object} with `start` and `end` properties
getCurrentLineRange: ->
row = @editorView.getCursor().getBufferRow()
lineLength = @editorView.lineLengthForBufferRow(row)
index = @editorView.editor.getBuffer().characterIndexForPosition({row: row, column: 0})
row = @editorView.getEditor().getCursor().getBufferRow()
lineLength = @editorView.getEditor().lineLengthForBufferRow(row)
index = @editorView.getEditor().getBuffer().characterIndexForPosition({row: row, column: 0})
return {
start: index,
end: index + lineLength
}

# Returns the current caret position.
getCaretPos: ->
row = @editorView.getCursor().getBufferRow()
column = @editorView.getCursor().getBufferColumn()
return @editorView.editor.getBuffer().characterIndexForPosition( {row: row, column: column} )
row = @editorView.getEditor().getCursor().getBufferRow()
column = @editorView.getEditor().getCursor().getBufferColumn()
return @editorView.getEditor().getBuffer().characterIndexForPosition( {row: row, column: column} )

# Sets the current caret position.
setCaretPos: (index) ->
pos = @editorView.editor.getBuffer().positionForCharacterIndex(index)
@editorView.editor.getSelection().clear()
@editorView.setCursorBufferPosition pos
pos = @editorView.getEditor().getBuffer().positionForCharacterIndex(index)
@editorView.getEditor().getSelection().clear()
@editorView.getEditor().setCursorBufferPosition pos

# Returns the current line.
getCurrentLine: ->
row = @editorView.getCursor().getBufferRow()
return @editorView.editor.lineForBufferRow(row)
row = @editorView.getEditor().getCursor().getBufferRow()
return @editorView.getEditor().lineForBufferRow(row)

# Replace the editor's content (or part of it, if using `start` to
# `end` index).
Expand Down Expand Up @@ -101,24 +101,26 @@ module.exports =
start: value.length + start
end: value.length + start

range = @editorView.getSelection().getBufferRange()
range.start = Point.fromObject(@editorView.editor.getBuffer().positionForCharacterIndex(start))
range.end = Point.fromObject(@editorView.editor.getBuffer().positionForCharacterIndex(end))
range = @editorView.getEditor().getSelection().getBufferRange()
changeRange = [
Point.fromObject(@editorView.getEditor().getBuffer().positionForCharacterIndex(start))
Point.fromObject(@editorView.getEditor().getBuffer().positionForCharacterIndex(end))
]

@editorView.editor.getBuffer().change(range, value)
@editorView.getEditor().getBuffer().change(changeRange, value)

range.start = Point.fromObject(@editorView.editor.getBuffer().positionForCharacterIndex(firstTabStop.start))
range.end = Point.fromObject(@editorView.editor.getBuffer().positionForCharacterIndex(firstTabStop.end))
range.start = Point.fromObject(@editorView.getEditor().getBuffer().positionForCharacterIndex(firstTabStop.start))
range.end = Point.fromObject(@editorView.getEditor().getBuffer().positionForCharacterIndex(firstTabStop.end))

@editorView.getSelection().setBufferRange(range)
@editorView.getEditor().getSelection().setBufferRange(range)

# Returns the editor content.
getContent: ->
return @editorView.getText()
return @editorView.getEditor().getText()

# Returns the editor's syntax mode.
getSyntax: ->
grammar = @editorView.editor.getGrammar().name
grammar = @editorView.getEditor().getGrammar().name
if /^CSS/.test(grammar)
return "css"
else if /^SCSS/.test(grammar)
Expand All @@ -136,16 +138,16 @@ module.exports =
#
# See emmet.setupProfile for more information.
getProfileName: ->
return @editorView.editor.getGrammar().name
return @editorView.getEditor().getGrammar().name

# Returns the currently selected text.
getSelection: ->
return @editorView.editor.getSelectedText()
return @editorView.getEditor().getSelectedText()

# Returns the current editor's file path
getFilePath: ->
# is there a better way to get this?
return @editorView.editor.buffer.file.path
return @editorView.getEditor().buffer.file.path

prompt: (message) ->
# does nothing. currently breaks decoding base64 URLs
2 changes: 1 addition & 1 deletion lib/emmet.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ module.exports =
syntax = editorProxy.getSyntax()
if emmet.require("resources").hasSyntax(syntax)
emmetAction = @actionTranslation[action]
if emmetAction == "expand_abbreviation_with_tab" && !editorView.getSelection().isEmpty()
if emmetAction == "expand_abbreviation_with_tab" && !editorView.getEditor().getSelection().isEmpty()
e.abortKeyBinding()
return
else
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "emmet",
"main": "./lib/emmet",
"version": "0.1.5",
"version": "0.1.6",
"private": true,
"dependencies": {
"season": "0.11.0"
Expand Down

0 comments on commit c2bb218

Please sign in to comment.