Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Allow pick commit on multi-line messages #601

Merged
merged 2 commits into from
Jun 4, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 53 additions & 5 deletions src/messages.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as path from "path";
import { commands, Uri, ViewColumn, WebviewPanel, window } from "vscode";
import { Model } from "./model";

export function noChangesToCommit() {
return window.showInformationMessage("There are no changes to commit.");
Expand Down Expand Up @@ -77,12 +78,15 @@ async function showCommitInput(message?: string, filePaths?: string[]) {
${beforeForm}
<form>
<fieldset>
<div class="float-right">
<a href="#" id="pickCommitMessage">Pick a previous commit message</a>
</div>
<label for="message">Commit message</label>
<textarea id="message" rows="5" placeholder="Message (press Ctrl+Enter to commit)"></textarea>
<button id="commit" class="button-primary">Commit</button>
<div class="float-right">
<button id="cancel" class="button button-outline">Cancel</button>
</div>
<textarea id="message" rows="3" placeholder="Message (press Ctrl+Enter to commit)"></textarea>
<button id="commit" class="button-primary">Commit</button>
<div class="float-right">
<button id="cancel" class="button button-outline">Cancel</button>
</div>
</fieldset>
</form>
</section>
Expand All @@ -92,6 +96,7 @@ async function showCommitInput(message?: string, filePaths?: string[]) {
const txtMessage = document.getElementById("message");
const btnCommit = document.getElementById("commit");
const btnCancel = document.getElementById("cancel");
const linkPickCommitMessage = document.getElementById("pickCommitMessage");

// load current message
txtMessage.value = ${JSON.stringify(message)};
Expand All @@ -116,11 +121,34 @@ async function showCommitInput(message?: string, filePaths?: string[]) {
}
});

// Auto resize the height of message
txtMessage.addEventListener("input", function(e) {
txtMessage.style.height = "auto";
txtMessage.style.height = (txtMessage.scrollHeight) + "px";
});

window.addEventListener("load", function() {
setTimeout(() => {
txtMessage.focus();
}, 1000);
});

linkPickCommitMessage.addEventListener("click", function() {
vscode.postMessage({
command: "pickCommitMessage"
});
});

// Message from VSCode
window.addEventListener("message", function(event) {
const message = event.data;
switch (message.command) {
case "setMessage":
txtMessage.value = message.message;
txtMessage.dispatchEvent(new Event("input"));
break;
}
});
</script>
</body>
</html>`;
Expand All @@ -132,13 +160,33 @@ async function showCommitInput(message?: string, filePaths?: string[]) {
resolve(undefined);
});

const pickCommitMessage = async () => {
let repository;

if (filePaths && filePaths[0]) {
const model = (await commands.executeCommand("svn.getModel", "")) as Model;
repository = await model.getRepositoryFromUri(Uri.file(filePaths[0]));
}

const message = await commands.executeCommand("svn.pickCommitMessage", repository);
if (message !== undefined) {
panel.webview.postMessage({
command: "setMessage",
message
});
}
};

// On button click
panel.webview.onDidReceiveMessage(message => {
switch (message.command) {
case "commit":
resolve(message.message);
panel.dispose();
break;
case "pickCommitMessage":
pickCommitMessage();
break;
default:
resolve(undefined);
panel.dispose();
Expand Down