Skip to content

Commit

Permalink
npm run build
Browse files Browse the repository at this point in the history
  • Loading branch information
aminya committed Apr 14, 2020
1 parent aa7daeb commit d16c82e
Show file tree
Hide file tree
Showing 2 changed files with 118 additions and 57 deletions.
23 changes: 23 additions & 0 deletions lib/misc/cells.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { Point, TextEditor } from "atom";
/**
* @param {TextEditor} editor
* @returns {[Point, Point]}
*/
export declare function getRange(editor: TextEditor): [Point, Point];
/**
* @param {TextEditor} editor
*/
export declare function get(editor: TextEditor): {
range: any[][];
selection: any;
line: any;
text: any;
}[];
/**
* @param {TextEditor | null | undefined} editor
*/
export declare function moveNext(editor: TextEditor | null | undefined): void | null;
/**
* @param {TextEditor | undefined | null} editor
*/
export declare function movePrev(editor: TextEditor | undefined | null): void | null;
152 changes: 95 additions & 57 deletions lib/misc/cells.js
Original file line number Diff line number Diff line change
@@ -1,109 +1,147 @@
'use babel'

import { get as weaveGet,
moveNext as weaveMoveNext,
movePrev as weaveMovePrev } from './weave.js'

import {
get as weaveGet,
moveNext as weaveMoveNext,
movePrev as weaveMovePrev,
} from './weave.js'
import { getLine } from './blocks.js'

import { Point } from 'atom'

export function getRange (ed) {
/**
* @param {TextEditor} editor
* @returns {[Point, Point]}
*/
export function getRange(editor) {
// Cell range is:
// Start of line below top delimiter (and/or start of top row of file) to
// End of line before end delimiter
var buffer = ed.getBuffer()
var start = buffer.getFirstPosition()
var end = buffer.getEndPosition()
var regexString = '^(' + atom.config.get('julia-client.uiOptions.cellDelimiter').join('|') + ')'
var regex = new RegExp(regexString)
var cursor = ed.getCursorBufferPosition()
const buffer = editor.getBuffer()
const start = buffer.getFirstPosition()
const end = buffer.getEndPosition()
const regexString =
'^(' +
atom.config.get('julia-client.uiOptions.cellDelimiter').join('|') +
')'
const regex = new RegExp(regexString)
const cursor = editor.getCursorBufferPosition()
cursor.column = Infinity // cursor on delimiter line means eval cell below


let foundDelim = false
for (let i = cursor.row + 1; i <= ed.getLastBufferRow(); i++) {
let {line, scope} = getLine(ed, i)
foundDelim = regex.test(line) && scope.join('.').indexOf('comment.line') > -1
for (let i = cursor.row + 1, l = editor.getLastBufferRow(); i <= l; i++) {
const { line, scope } = getLine(editor, i)
foundDelim =
regex.test(line) && scope.join('.').indexOf('comment.line') > -1
end.row = i
if (foundDelim) break
}

if (foundDelim) {
end.row -= 1
if (end.row < 0) end.row = 0
end.column = Infinity
}

foundDelim = false
if (cursor.row > 0) {
for (let i = end.row; i >= 0; i--) {
let {line, scope} = getLine(ed, i)
foundDelim = regex.test(line) && scope.join('.').indexOf('comment.line') > -1
const { line, scope } = getLine(editor, i)
foundDelim =
regex.test(line) && scope.join('.').indexOf('comment.line') > -1
start.row = i
if (foundDelim) {
break
}
}
start.column = 0
}

return [start, end]
}

export function get (ed) {
if (ed.getGrammar().scopeName.indexOf('source.julia') > -1) {
return jlGet(ed)
/**
* @param {TextEditor} editor
*/
export function get(editor) {
if (editor.getGrammar().scopeName.indexOf('source.julia') > -1) {
return jlGet(editor)
} else {
return weaveGet(ed)
return weaveGet(editor)
}
}

function jlGet (ed) {
var range = getRange(ed)
var text = ed.getTextInBufferRange(range)
/**
* @param {TextEditor} editor
*/
function jlGet(editor) {
const range = getRange(editor)
let text = editor.getTextInBufferRange(range)
if (text.trim() === '') text = ' '
var res = {
range: [[range[0].row, range[0].column], [range[1].row, range[1].column]],
selection: ed.getSelections()[0],
const res = {
range: [
[range[0].row, range[0].column],
[range[1].row, range[1].column],
],
selection: editor.getSelections()[0],
line: range[0].row,
text: text
text: text,
}
return [res]
}

export function moveNext (ed) {
if (ed == null) {
ed = atom.workspace.getActiveTextEditor()
/**
* @param {TextEditor | null | undefined} editor
*/
export function moveNext(editor) {
if (!editor) {
editor = atom.workspace.getActiveTextEditor()
}
if (ed.getGrammar().scopeName.indexOf('source.julia') > -1) {
return jlMoveNext(ed)
// TODO: getActiveTextEditor may return undefined
if (editor) {
if (editor.getGrammar().scopeName.indexOf('source.julia') > -1) {
return jlMoveNext(editor)
} else {
return weaveMoveNext(editor)
}
} else {
return weaveMoveNext(ed)
console.error('No editor is given')
}
}

function jlMoveNext (ed) {
var range = getRange(ed)
var sel = ed.getSelections()[0]
var nextRow = range[1].row + 2 // 2 = 1 to get to delimiter line + 1 more to go past it
return sel.setBufferRange([[nextRow, 0], [nextRow, 0]])
/**
* @param {TextEditor} editor
*/
function jlMoveNext(editor) {
const range = getRange(editor)
const sel = editor.getSelections()[0]
const nextRow = range[1].row + 2 // 2 = 1 to get to delimiter line + 1 more to go past it
return sel.setBufferRange([
[nextRow, 0],
[nextRow, 0],
])
}

export function movePrev (ed) {
if (ed == null) {
ed = atom.workspace.getActiveTextEditor()
/**
* @param {TextEditor | undefined | null} editor
*/
export function movePrev(editor) {
if (!editor) {
editor = atom.workspace.getActiveTextEditor()
}
if (ed.getGrammar().scopeName.indexOf('source.weave') > -1) {
return weaveMovePrev(ed)
if (editor) {
if (editor.getGrammar().scopeName.indexOf('source.weave') > -1) {
return weaveMovePrev(editor)
} else {
return jlMovePrev(editor)
}
} else {
return jlMovePrev(ed)
console.error('No editor is given')
}
}

function jlMovePrev (ed) {
var range = getRange(ed)
var prevRow = range[0].row - 2 // 2 = 1 to get to delimiter line + 1 more to go past it
var sel = ed.getSelections()[0]
return sel.setBufferRange([[prevRow, 0], [prevRow, 0]])
/**
* @param {TextEditor} editor
*/
function jlMovePrev(editor) {
const range = getRange(editor)
const prevRow = range[0].row - 2 // 2 = 1 to get to delimiter line + 1 more to go past it
const sel = editor.getSelections()[0]
return sel.setBufferRange([
[prevRow, 0],
[prevRow, 0],
])
}

0 comments on commit d16c82e

Please sign in to comment.