From 37b48f0c81dd7b06aa09e432384f0e279f811630 Mon Sep 17 00:00:00 2001 From: Bati Sengul Date: Thu, 21 Sep 2017 13:12:18 +0300 Subject: [PATCH] Revert "Enable \ref from any subfolders just like \cite" --- lib/label-view.coffee | 20 ++++++----- lib/list-labels.js | 80 ------------------------------------------- 2 files changed, 12 insertions(+), 88 deletions(-) delete mode 100644 lib/list-labels.js diff --git a/lib/label-view.coffee b/lib/label-view.coffee index 27292f8..c840877 100644 --- a/lib/label-view.coffee +++ b/lib/label-view.coffee @@ -1,8 +1,6 @@ {$,SelectListView} = require 'atom-space-pen-views' FindLabels = require './find-labels' -ListLabels = require './list-labels' fs = require 'fs-plus' -pathModule = require 'path' module.exports = class LabelView extends SelectListView @@ -18,12 +16,18 @@ class LabelView extends SelectListView @editor = editor file = editor?.buffer?.file basePath = file?.path - activePaneItemPath = basePath - texRootRex = /%(\s+)?!TEX root(\s+)?=(\s+)?(.+)/g + texRootRex = /%!TEX root = (.+)/g while(match = texRootRex.exec(@editor.getText())) - absolutFilePath = FindLabels.getAbsolutePath(activePaneItemPath,match[4]) - basePath = pathModule.dirname(absolutFilePath) - labels = ListLabels.fromDir(basePath, /\.tex$/); + absolutFilePath = FindLabels.getAbsolutePath(basePath,match[1]) + try + text = fs.readFileSync(absolutFilePath).toString() + labels = FindLabels.getLabelsByText(text, absolutFilePath) + catch error + errmsg = 'could not load content of #{absolutFilePath}' + atom.notifications.addError(errmsg, { dismissable: true }) + console.log(error) + if labels == undefined or labels.length == 0 + labels = FindLabels.getLabelsByText(@editor.getText(), basePath) @setItems(labels) @panel ?= atom.workspace.addModalPanel(item: this) @panel.show() @@ -40,7 +44,7 @@ class LabelView extends SelectListView "label" viewForItem: ({label}) -> - "
  • #{label}
  • " + "
  • #{label}
  • " confirmed: ({label}) -> @editor.insertText label diff --git a/lib/list-labels.js b/lib/list-labels.js deleted file mode 100644 index 25a6178..0000000 --- a/lib/list-labels.js +++ /dev/null @@ -1,80 +0,0 @@ -/* - * decaffeinate suggestions: - * DS102: Remove unnecessary code created because of implicit returns - * DS207: Consider shorter variations of null checks - * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md - */ -let ListLabels; -const fsPlus = require('fs-plus'); -const fs = require('fs-plus'); -const path = require('path'); - -module.exports = -(ListLabels = { - fromDir(startPath,filter){ - allLabels = [] - if (!fs.existsSync(startPath)){ - console.log("no dir ",startPath); - return; - } - - var files=fs.readdirSync(startPath); - for(var i=0;i