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

Commit

Permalink
Merge pull request #4 from openmainframeproject/development
Browse files Browse the repository at this point in the history
Improve addRevisionBars command behavior in a common corner case
  • Loading branch information
johnarwe authored Dec 29, 2017
2 parents 5536cd3 + b9e6f01 commit 8d49ab8
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 30 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
## 0.1.3 - New function to add BookMaster revision bars
* Change `addRevisionBars` command to improve its handling of a corner case that matters when trying to properly nest different revision tags.
* If the user selects nothing, the current cursor line(s) are wrapped.
* (changed) If the user selects exactly 1 line (left margin, shift down arrow), wrap only the selected line. (in 0.1.2, the line with the cursor would also be wrapped)
* If the user selects any other text, all lines within each selection are wrapped.
* In addition to the existing CTL-ALT-V binding, added command to editor context menu.

## 0.1.2 - New function to add BookMaster revision bars
* New `addRevisionBars` command to add :rev/:erev around current editor cursor(s), mapped to CTL-ALT-V by default, with the refid value supplied in a package setting

Expand Down
45 changes: 26 additions & 19 deletions lib/language-zvm-gml.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -56,30 +56,37 @@ module.exports = LanguageZvmGml =
# because it's inserting text, and ranges do not get adjusted for
# inserts on the fly (while markers do get adjusted).
addRevisionBars: ->
editor = atom.workspace.getActiveTextEditor()
console.log "addRevisionBars ", editor if @debugging
if editor?
selectedRanges = editor.getSelectedBufferRanges()
selectedMarkers = []
markerProperties = { "invalidate": "never"}
selectedMarkers.push( editor.markBufferRange(oneRange,markerProperties) ) for oneRange , i in selectedRanges
console.log "addRevisionBars markers ", selectedMarkers if @debugging
@addRevisionBarsToRange editor, m for m in selectedMarkers

addRevisionBarsToRange: (editor, oneMarker) ->
r = oneMarker.getBufferRange()
console.log "addRevisionBarsToRange: ", editor, oneMarker , r if @debugging
console.log "addRevisionBars entry" if @debugging
refid = atom.config.get @userVisiblePackageName+".revisionRefid"
if refid
editor.setCursorBufferPosition([r.start.row , 0])
editor.insertText(":rev refid=" + refid + ".\n")
# Update the range, whose bounds do not reflect the just-inserted text
r = oneMarker.getBufferRange()
editor.setCursorBufferPosition([r.end.row+1 , 0])
editor.insertText(":erev refid=" + refid + ".\n")
beforeText = ":rev refid=" + refid + ".\n"
afterText = ":erev refid=" + refid + ".\n"
editor = atom.workspace.getActiveTextEditor()
console.log "addRevisionBars ", editor if @debugging
if editor?
selectedRanges = editor.getSelectedBufferRanges()
selectedMarkers = []
markerProperties = { "invalidate": "never"}
selectedMarkers.push( editor.markBufferRange(oneRange,markerProperties) ) for oneRange , i in selectedRanges
console.log "addRevisionBars markers ", selectedMarkers if @debugging
@addRevisionBarsToRange editor, m, beforeText, afterText for m in selectedMarkers
else
atom.notifications.addWarning("The revision's refid is empty. Set the value in the package's settings.",
{dismissable:true,
detail: "Open File > Settings > Packages, filter on " + @userVisiblePackageName +
", click on the Settings control for that package, scroll to its Settings section, " +
"and set it to a non-blank value."})

addRevisionBarsToRange: (editor, oneMarker, beforeText, afterText) ->
r = oneMarker.getBufferRange()
if r.start.row != r.end.row and r.start.column == 0 and r.end.column == 0
countFinalRow = 0 # Manually selected an entire line "the easy way"
else
countFinalRow = 1
console.log "addRevisionBarsToRange: ", editor, oneMarker , r , countFinalRow if @debugging
editor.setCursorBufferPosition([r.start.row , 0])
editor.insertText(beforeText)
# Update the range, whose bounds do not reflect the just-inserted text
r = oneMarker.getBufferRange()
editor.setCursorBufferPosition([r.end.row+countFinalRow , 0])
editor.insertText(afterText)
14 changes: 7 additions & 7 deletions menus/language-zvm-gml.cson
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
# in case default menu entries are needed in the future.

# See https://atom.io/docs/latest/hacking-atom-package-word-count#menus for more details
#'context-menu':
# 'atom-text-editor': [
# {
# 'label': 'Toggle language-zvm-gml'
# 'command': 'language-zvm-gml:toggle'
# }
# ]
'context-menu':
'atom-text-editor': [
{
'label': 'Add revision bars around selection(s)'
'command': 'language-zvm-gml:addRevisionBars'
}
]
#'menu': [
# {
# 'label': 'Packages'
Expand Down
16 changes: 12 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,24 +1,32 @@
{
"name": "language-zvm-gml",
"main": "./lib/language-zvm-gml",
"version": "0.1.2",
"version": "0.1.3",
"description": "Syntax highlighting for z/VM SCRIPT files, containing Script and/or BookMaster tags",
"keywords": [
"language",
"grammar",
"z/VM",
"syntax"
],
"repository": "https://github.com/openmainframeproject/atompkg-language-zvm-gml",
"license": "Apache 2",
"comment": "See NOTICE.md for copyright notices",
"activationCommands": {
"atom-workspace": "language-zvm-gml:toggle",
"atom-text-editor": "language-zvm-gml:addRevisionBars"
},
"activationHooks": [
"language-zvm-gml:grammar-used"
],
"repository": "https://github.com/openmainframeproject/atompkg-language-zvm-gml",
"license": "Apache 2",
"comment": "See NOTICE.md for copyright notices",
"context-menu": {
"atom-text-editor": [
{
"label": "Add revision bars around selection(s)",
"command": "language-zvm-gml:addRevisionBars"
}
]
},
"engines": {
"atom": ">=1.0.0 <2.0.0"
},
Expand Down

0 comments on commit 8d49ab8

Please sign in to comment.