Skip to content
This repository has been archived by the owner on Dec 15, 2022. It is now read-only.

Commit

Permalink
run prettier on the files
Browse files Browse the repository at this point in the history
  • Loading branch information
aminya committed Apr 12, 2020
1 parent 5ccc119 commit 162618d
Show file tree
Hide file tree
Showing 8 changed files with 294 additions and 136 deletions.
51 changes: 36 additions & 15 deletions lib/cursor-position-view.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
'use babel'
'use babel';
/*
* decaffeinate suggestions:
* DS207: Consider shorter variations of null checks
Expand All @@ -9,7 +9,6 @@ import { Disposable } from 'atom';

export default CursorPositionView = class CursorPositionView {
constructor() {

this.viewUpdatePending = false;

this.element = document.createElement('status-bar-cursor');
Expand All @@ -21,12 +20,16 @@ export default CursorPositionView = class CursorPositionView {
let left = atom.config.get('status-bar.cursorPositionFormat');
this.formatString = left != null ? left : '%L:%C';

this.activeItemSubscription = atom.workspace.onDidChangeActiveTextEditor(activeEditor => this.subscribeToActiveTextEditor());
this.activeItemSubscription = atom.workspace.onDidChangeActiveTextEditor(
activeEditor => this.subscribeToActiveTextEditor()
);

this.subscribeToConfig();
this.subscribeToActiveTextEditor();

this.tooltip = atom.tooltips.add(this.element, {title: () => `Line ${this.row}, Column ${this.column}`});
this.tooltip = atom.tooltips.add(this.element, {
title: () => `Line ${this.row}, Column ${this.column}`
});

this.handleClick();
}
Expand All @@ -41,7 +44,9 @@ export default CursorPositionView = class CursorPositionView {
this.configSubscription.dispose();
}
this.clickSubscription.dispose();
this.updateSubscription != null ? this.updateSubscription.dispose() : undefined;
this.updateSubscription != null
? this.updateSubscription.dispose()
: undefined;
}

subscribeToActiveTextEditor() {
Expand All @@ -50,33 +55,47 @@ export default CursorPositionView = class CursorPositionView {
}

const editor = atom.workspace.getActiveTextEditor();
let selectionsMarkerLayer
let selectionsMarkerLayer;
if (editor) {
selectionsMarkerLayer = editor.selectionsMarkerLayer;
}

this.cursorSubscription = selectionsMarkerLayer != null ? selectionsMarkerLayer.onDidUpdate(this.scheduleUpdate.bind(this)) : undefined;
this.cursorSubscription =
selectionsMarkerLayer != null
? selectionsMarkerLayer.onDidUpdate(this.scheduleUpdate.bind(this))
: undefined;
this.scheduleUpdate();
}

subscribeToConfig() {
if (this.configSubscription != null) {
this.configSubscription.dispose();
}
this.configSubscription = atom.config.observe('status-bar.cursorPositionFormat', value => {
this.formatString = value != null ? value : '%L:%C';
this.scheduleUpdate();
});
this.configSubscription = atom.config.observe(
'status-bar.cursorPositionFormat',
value => {
this.formatString = value != null ? value : '%L:%C';
this.scheduleUpdate();
}
);
}

handleClick() {
const clickHandler = () => atom.commands.dispatch(atom.views.getView(atom.workspace.getActiveTextEditor()), 'go-to-line:toggle');
const clickHandler = () =>
atom.commands.dispatch(
atom.views.getView(atom.workspace.getActiveTextEditor()),
'go-to-line:toggle'
);
this.element.addEventListener('click', clickHandler);
this.clickSubscription = new Disposable(() => this.element.removeEventListener('click', clickHandler));
this.clickSubscription = new Disposable(() =>
this.element.removeEventListener('click', clickHandler)
);
}

scheduleUpdate() {
if (this.viewUpdatePending) { return; }
if (this.viewUpdatePending) {
return;
}

this.viewUpdatePending = true;
this.updateSubscription = atom.views.updateDocument(() => {
Expand All @@ -91,7 +110,9 @@ export default CursorPositionView = class CursorPositionView {
if (position) {
this.row = position.row + 1;
this.column = position.column + 1;
this.goToLineLink.textContent = this.formatString.replace('%L', this.row).replace('%C', this.column);
this.goToLineLink.textContent = this.formatString
.replace('%L', this.row)
.replace('%C', this.column);
this.element.classList.remove('hide');
} else {
this.goToLineLink.textContent = '';
Expand Down
68 changes: 41 additions & 27 deletions lib/file-info-view.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
'use babel'
'use babel';
/*
* decaffeinate suggestions:
* Amin: Simplify Optional Chaining at 117 and 130 inside subscribeToActiveItem
Expand All @@ -22,9 +22,11 @@ export default FileInfoView = class FileInfoView {

this.element.getActiveItem = this.getActiveItem.bind(this);

this.activeItemSubscription = atom.workspace.getCenter().onDidChangeActivePaneItem(() => {
this.subscribeToActiveItem();
});
this.activeItemSubscription = atom.workspace
.getCenter()
.onDidChangeActivePaneItem(() => {
this.subscribeToActiveItem();
});
this.subscribeToActiveItem();

this.registerTooltip();
Expand All @@ -35,19 +37,21 @@ export default FileInfoView = class FileInfoView {
atom.clipboard.write(text);
setTimeout(() => {
this.clearCopiedTooltip();
}
, 2000);
}, 2000);
};

this.element.addEventListener('click', clickHandler);
this.clickSubscription = new Disposable(() => this.element.removeEventListener('click', clickHandler));
this.clickSubscription = new Disposable(() =>
this.element.removeEventListener('click', clickHandler)
);
}

registerTooltip() {
this.tooltip = atom.tooltips.add(this.element, { title() {
return "Click to copy absolute file path (Shift + Click to copy relative path)";
}
});
this.tooltip = atom.tooltips.add(this.element, {
title() {
return 'Click to copy absolute file path (Shift + Click to copy relative path)';
}
});
}

clearCopiedTooltip() {
Expand All @@ -71,8 +75,7 @@ export default FileInfoView = class FileInfoView {
delay: {
show: 0
}
}
);
});
}

getActiveItemCopyText(copyRelativePath) {
Expand All @@ -83,7 +86,9 @@ export default FileInfoView = class FileInfoView {
path = activeItem.getPath();
}

if ((path == null)) { return activeItem.getTitle() || ''; }
if (path == null) {
return activeItem.getTitle() || '';
}

// Make sure we try to relativize before parsing URLs.
if (copyRelativePath) {
Expand All @@ -95,9 +100,7 @@ export default FileInfoView = class FileInfoView {

// An item path could be a url, we only want to copy the `path` part
if ((path != null ? path.indexOf('://') : undefined) > 0) {
({
path
} = url.parse(path));
({ path } = url.parse(path));
}
return path;
}
Expand All @@ -111,23 +114,33 @@ export default FileInfoView = class FileInfoView {
}
let activeItem = this.getActiveItem();
if (activeItem) {
if (this.updateCallback == null) { this.updateCallback = () => this.update(); }
if (this.updateCallback == null) {
this.updateCallback = () => this.update();
}

// optional chaining:
if (typeof activeItem.onDidChangeTitle === 'function') {
this.titleSubscription = activeItem.onDidChangeTitle(this.updateCallback);
this.titleSubscription = activeItem.onDidChangeTitle(
this.updateCallback
);
} else if (typeof activeItem.on === 'function') {
//TODO Remove once title-changed event support is removed
activeItem.on('title-changed', this.updateCallback);
this.titleSubscription = { dispose: () => {
this.titleSubscription = {
dispose: () => {
// optional chaining:
return (typeof activeItem.off === 'function' ? activeItem.off('title-changed', this.updateCallback) : undefined);
}
};
return typeof activeItem.off === 'function'
? activeItem.off('title-changed', this.updateCallback)
: undefined;
}
};
}

// optional chaining:
this.modifiedSubscription = typeof activeItem.onDidChangeModified === 'function' ? activeItem.onDidChangeModified(this.updateCallback) : undefined;
this.modifiedSubscription =
typeof activeItem.onDidChangeModified === 'function'
? activeItem.onDidChangeModified(this.updateCallback)
: undefined;
}

this.update();
Expand Down Expand Up @@ -185,16 +198,17 @@ export default FileInfoView = class FileInfoView {
return;
}

if (typeof activeItem.getPath == "function") {
if (typeof activeItem.getPath == 'function') {
let path = activeItem.getPath();
if (path) {
const relativized = atom.project.relativize(path);
this.currentPath.textContent = (relativized != null) ? fs.tildify(relativized) : path;
this.currentPath.textContent =
relativized != null ? fs.tildify(relativized) : path;
return;
}
}

if (typeof activeItem.getTitle == "function") {
if (typeof activeItem.getTitle == 'function') {
let title = activeItem.getTitle();
if (title) {
this.currentPath.textContent = title;
Expand Down
Loading

0 comments on commit 162618d

Please sign in to comment.