Skip to content

Commit

Permalink
Fixing bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
lostintangent committed Dec 14, 2019
1 parent 2e2b540 commit f9d9c08
Show file tree
Hide file tree
Showing 15 changed files with 195 additions and 94 deletions.
7 changes: 5 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
## v0.0.17 (12/12/2019)

- Added a new `Open Gist in NbViewer` context menu to gists, that allows you to open Gists with Jupyter Notebooks in the [Jupyter Nbviewer](https://nbviewer.jupyter.org/)
- Introduced a new `Gistpad: Always Show Comments` configuration option, that allows you to specify whether you want to always view comments when you open a Gist file
- Fixed a bug, that impacted Gist files with special characters in their name (e.g. `*`, `?`)
-
- Fixed a bug with comment threads, that ensure they're always displayed at the bottom of the file, even after making edits

## v0.0.16 (12/11/2019)

- Added a new `Clone Repository` context menu to gists, that allows you to clone a gist's repository locally
- Added a new `Open Gist in GistLog` context menu to gists, that allows you to view a Gist in [GistLog](https://gistlog.co)
- Introduced a new `gistpad.apiUrl` setting, which allows users to use GitHub Enterprise servers

## v0.0.15 (12/08/2019)

- Added support for opening image files in a Gist, and viewing their preview
Expand Down
18 changes: 10 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ Paste screenshots from your clipboard into the gist:

![paste-screenshot](https://user-images.githubusercontent.com/1478800/70382701-9a7ac980-1914-11ea-9fb0-6e55424e2e54.gif)

- From the editor's context menu: `Paste Screenshot` command (this only appears within GistPad-managed markdown files).
- From command palette: `GistPad: Paste Screenshot` command.
- Keyboard shortcut:
- Windows/Linux: `ctrl + shift + v`
- Mac OSx: `cmd + shift + v`
- From the editor's context menu: `Paste Screenshot` command (this only appears within GistPad-managed markdown files).
- From command palette: `GistPad: Paste Screenshot` command.
- Keyboard shortcut:
- Windows/Linux: `ctrl + shift + v`
- Mac OSx: `cmd + shift + v`

By default the screenshot gets uploaded as a `.png` file to the gist and the link is added to the gist as `Markdown` image markup. The behaviour can be changed using the follow settings:

Expand Down Expand Up @@ -110,7 +110,9 @@ In addition to the `Gists` view, this extension also provides the following comm

## Configuration Settings

- `Gistpad: Api Url` - Specified the GitHub API server to use. By default, this points at GitHub.com (`https://api.github.com`), but if you're using GitHub Enterprise, then you need to set this to the v3 API URL of your GitHub server. This should be something like `https://[YOUR_HOST]/api/v3`.
- `GistPad: Always Show Comments` - Specifies whether to always show the comment thread UI whenever you open a Gist file. Defaults to `false`.

- `Gistpad: Api Url` - Specifies the GitHub API server to use. By default, this points at GitHub.com (`https://api.github.com`), but if you're using GitHub Enterprise, then you need to set this to the v3 API URL of your GitHub server. This should be something like `https://[YOUR_HOST]/api/v3`.

- `Gistpad: Paste Screenshot Type`:

Expand All @@ -126,8 +128,8 @@ In addition to the `Gists` view, this extension also provides the following comm

- `Paste Screenshot` command:

- Windows/Linux: `ctrl + shift + v`
- Mac OSx: `cmd + shift + v`
- Windows/Linux: `ctrl + shift + v`
- Mac OSx: `cmd + shift + v`

## Supported Filesystem Operations

Expand Down
50 changes: 39 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"displayName": "GistPad",
"description": "Browse, edit and fork GitHub Gists, directly within Visual Studio Code",
"publisher": "vsls-contrib",
"version": "0.0.16",
"version": "0.0.17",
"icon": "images/icon.png",
"repository": {
"type": "git",
Expand Down Expand Up @@ -156,6 +156,11 @@
"title": "Open Gist Files",
"category": "GistPad"
},
{
"command": "gistpad.openGistFile",
"title": "Open Gist File",
"category": "GistPad"
},
{
"command": "gistpad.openGistInBrowser",
"title": "Open Gist in GitHub",
Expand All @@ -166,6 +171,11 @@
"title": "Open Gist in GistLog",
"category": "GistPad"
},
{
"command": "gistpad.openGistInNbViewer",
"title": "Open Gist in NbViewer",
"category": "GistPad"
},
{
"command": "gistpad.openGistWorkspace",
"title": "Open Gist as Workspace",
Expand Down Expand Up @@ -284,6 +294,10 @@
"command": "gistpad.editGistComment",
"when": "false"
},
{
"command": "gistpad.openGistFile",
"when": "false"
},
{
"command": "gistpad.openGistInBrowser",
"when": "false"
Expand All @@ -292,6 +306,10 @@
"command": "gistpad.openGistInGistLog",
"when": "false"
},
{
"command": "gistpad.openGistInNbViewer",
"when": "false"
},
{
"command": "gistpad.pasteGistFile",
"when": "false"
Expand Down Expand Up @@ -350,32 +368,37 @@
"view/item/context": [
{
"command": "gistpad.openGist",
"when": "viewItem == gists.gist || viewItem == starredGists.gist || viewItem == followedUser.gist",
"when": "viewItem =~ /gists.gist/ || viewItem =~ /starredGists.gist/ || viewItem =~ /followedUser.gist/",
"group": "base@1"
},
{
"command": "gistpad.openGistWorkspace",
"when": "viewItem == gists.gist || viewItem == starredGists.gist || viewItem == followedUser.gist",
"when": "viewItem =~ /gists.gist/ || viewItem =~ /starredGists.gist/ || viewItem =~ /followedUser.gist/",
"group": "base@2"
},
{
"command": "gistpad.openGistInBrowser",
"when": "viewItem == gists.gist || viewItem == starredGists.gist || viewItem == followedUser.gist",
"when": "viewItem =~ /gists.gist/ || viewItem =~ /starredGists.gist/ || viewItem =~ /followedUser.gist/",
"group": "browse@1"
},
{
"command": "gistpad.openGistInGistLog",
"when": "viewItem == gists.gist || viewItem == starredGists.gist || viewItem == followedUser.gist",
"group": "browse@2"
},
{
"command": "gistpad.openGistInNbViewer",
"when": "viewItem == gists.gist.notebook || viewItem == starredGists.gist.notebook || viewItem == followedUser.gist.notebook",
"group": "browse@2"
},
{
"command": "gistpad.copyGistUrl",
"when": "viewItem == gists.gist || viewItem == starredGists.gist || viewItem == followedUser.gist",
"when": "viewItem =~ /gists.gist/ || viewItem =~ /starredGists.gist/ || viewItem =~ /followedUser.gist/",
"group": "copy@1"
},
{
"command": "gistpad.cloneRepository",
"when": "viewItem == gists.gist || viewItem == starredGists.gist || viewItem == followedUser.gist",
"when": "viewItem =~ /gists.gist/ || viewItem =~ /starredGists.gist/ || viewItem =~ /followedUser.gist/",
"group": "copy@2"
},
{
Expand Down Expand Up @@ -514,6 +537,16 @@
"type": "object",
"title": "GistPad",
"properties": {
"gistpad.alwaysShowComments": {
"default": false,
"type": "boolean",
"description": "Specifies whether the comment thread UI should always be displayed when you open a Gist file."
},
"gistpad.apiUrl": {
"default": "https://api.github.com",
"type": "string",
"description": "Specifies the GitHub server's API URL. By default, this points to GitHub.com, but it can be used to point at a GitHub Enterprise instance."
},
"gistpad.pasteScreenshotOutput": {
"default": "markdown",
"enum": [
Expand All @@ -529,11 +562,6 @@
"base64"
],
"description": "Upload pasted screenshot to the Gist as a file or Base64-embed it to the gist."
},
"gistpad.apiUrl": {
"default": "https://api.github.com",
"type": "string",
"description": "Specifies the GitHub server's API URL. By default, this points to GitHub.com, but it can be used to point at a GitHub Enterprise instance."
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/abstractions/node/commands/pasteImage.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as vscode from "vscode";
import * as config from "../../../config/config";
import * as config from "../../../config";
import { log } from "../../../logger";
import { createCommand } from "../../../utils/createCommand";
import { createUploadMarkup } from "../../../utils/createUploadMarkup";
Expand All @@ -19,7 +19,7 @@ const tryToRemoveUploadingMarkup = async (
throw new Error("No active text editor to paste the image.");
}

editor.edit(edit => {
editor.edit((edit) => {
const { document } = editor;
const text = document.getText();

Expand Down Expand Up @@ -50,7 +50,7 @@ const addUploadingMarkup = async (id: string | number) => {

const markup = createUploadMarkup(id, isUploading);

await editor.edit(edit => {
await editor.edit((edit) => {
const current = editor.selection;

if (current.isEmpty) {
Expand Down
22 changes: 16 additions & 6 deletions src/commands/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ import {
env,
ExtensionContext,
ProgressLocation,
Uri,
window,
workspace,
workspace
} from "vscode";
import { EXTENSION_ID } from "../constants";
import { addGistFiles } from "../store/actions";
import { ensureAuthenticated } from "../store/auth";
import { GistFileNode, GistNode } from "../tree/nodes";
import { fileNameToUri } from "../utils";
import { fileNameToUri, openGistFile } from "../utils";

export function registerFileCommands(context: ExtensionContext) {
context.subscriptions.push(
Expand All @@ -25,7 +26,7 @@ export function registerFileCommands(context: ExtensionContext) {
if (window.activeTextEditor.document.isUntitled) {
filename = await window.showInputBox({
prompt: "Enter a name to give to this file",
value: "foo.txt",
value: "foo.txt"
});

if (!filename) {
Expand All @@ -40,7 +41,7 @@ export function registerFileCommands(context: ExtensionContext) {
window.withProgress(
{
location: ProgressLocation.Notification,
title: "Adding files...",
title: "Adding files..."
},
() => {
const content = window.activeTextEditor!.document.getText();
Expand Down Expand Up @@ -68,7 +69,7 @@ export function registerFileCommands(context: ExtensionContext) {
const fileName = await window.showInputBox({
prompt:
"Enter the files name(s) to seed the Gist with (can be a comma-seperated list)",
value: "foo.txt",
value: "foo.txt"
});
if (!fileName) {
return;
Expand Down Expand Up @@ -120,6 +121,15 @@ export function registerFileCommands(context: ExtensionContext) {
)
);

context.subscriptions.push(
commands.registerCommand(
`${EXTENSION_ID}.openGistFile`,
async (uri: Uri) => {
openGistFile(uri);
}
)
);

context.subscriptions.push(
commands.registerCommand(
`${EXTENSION_ID}.renameFile`,
Expand All @@ -128,7 +138,7 @@ export function registerFileCommands(context: ExtensionContext) {

const newFilename = await window.showInputBox({
prompt: "Specify the new name for this file",
value: node.file.filename,
value: node.file.filename
});

if (!newFilename) {
Expand Down
37 changes: 21 additions & 16 deletions src/commands/gist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,6 @@ interface IOpenGistOptions {
gistUrl?: string;
gistId?: string;
}
const openGistOptionsDefaults: IOpenGistOptions = {
openAsWorkspace: false
} as const;

const openGistById = (id: string, openAsWorkspace: boolean) => {
if (openAsWorkspace) {
Expand All @@ -107,26 +104,20 @@ const getGistIdFromUrl = (gistUrl: string) => {
return id;
};

async function openGistInternal(options: IOpenGistOptions = {}) {
options = {
...openGistOptionsDefaults,
...options
};

async function openGistInternal(
options: IOpenGistOptions = { openAsWorkspace: false }
) {
const { node, openAsWorkspace, gistUrl, gistId } = options;

if (gistUrl || gistId) {
const id = gistId ? gistId : getGistIdFromUrl(gistUrl!); // (!) since the `gistId` is not set, means the `gistUrl` is set

return openGistById(id, !!openAsWorkspace);
}

let gistItems: GistQuickPickItem[] = [];

if (node) {
} else if (node) {
return openGistById(node.gist.id, !!openAsWorkspace);
}

let gistItems: GistQuickPickItem[] = [];
if (await isAuthenticated()) {
const gists = await listGists();

Expand Down Expand Up @@ -360,7 +351,9 @@ export async function registerGistCommands(context: ExtensionContext) {
);

context.subscriptions.push(
commands.registerCommand(CommandId.openGist, openGistInternal)
commands.registerCommand(CommandId.openGist, (node?: GistNode) => {
openGistInternal({ node });
})
);

context.subscriptions.push(
Expand All @@ -382,10 +375,22 @@ export async function registerGistCommands(context: ExtensionContext) {
)
);

context.subscriptions.push(
commands.registerCommand(
`${EXTENSION_ID}.openGistInNbViewer`,
async (node: GistNode) => {
const url = `https://nbviewer.jupyter.org/gist/${node.gist.owner.login}/${node.gist.id}`;
env.openExternal(Uri.parse(url));
}
)
);

context.subscriptions.push(
commands.registerCommand(
`${EXTENSION_ID}.openGistWorkspace`,
openGistInternal.bind(null, { openAsWorkspace: true })
(node?: GistNode) => {
openGistInternal({ node, openAsWorkspace: true });
}
)
);

Expand Down

0 comments on commit f9d9c08

Please sign in to comment.