Skip to content

Commit

Permalink
add keyboard support
Browse files Browse the repository at this point in the history
  • Loading branch information
leftstick committed May 15, 2017
1 parent 27e9da7 commit fb0c1ee
Show file tree
Hide file tree
Showing 17 changed files with 816 additions and 275 deletions.
452 changes: 452 additions & 0 deletions .esformatter

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions .vscodeignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ src/**
.gitignore
tsconfig.json
vsc-extension-quickstart.md
images/**
80 changes: 80 additions & 0 deletions assets/css/gitk.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
* {
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: monospace;
}
html, body {
width: 100%;
max-width: 100%;
height: 100%;
max-height: 100%;
}
.container {
display: flex;
flex-direction: column;
width: 100%;
max-width: 100%;
height: 100%;
max-height: 100%;
flex-grow: 0;
}
.commits {
display: flex;
flex-direction: column;
height: 300px;
min-height: 300px;
flex-shrink: 0;
border-bottom: 1px solid #fff;
overflow-y: auto;
}
.commits:focus {
outline: none;
}
.detail {
overflow: auto;
flex-grow: 0;
}

.commit {
display: flex;
flex-direction: row;
justify-content: space-between;
margin-top: 3px;
margin-bottom: 3px;
cursor: pointer;
flex-shrink: 0;
text-decoration: none;
color: #fff;
}
.commit:focus {
outline: none;
}

.commit.selected {
font-weight: bold;
color: #80da51;
}

.commit > div {
margin-left: 5px;
margin-right: 5px;
}

.commit .hash {
width: 80px;
flex-shrink: 0;
}

.commit .message {
flex: 2;
text-overflow: ellipsis;
overflow: hidden;
white-space: nowrap;
}

.commit .date {
width: 200px;
text-align: right;
flex-shrink: 0;
}
35 changes: 35 additions & 0 deletions assets/js/copyHash.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
(function(document, global) {

document.querySelector('.commits').addEventListener('dblclick', (e) => {
const cNode = global.getCommitNode(e.target);
if (!cNode) {
return;
}
copyTextToClipboard(cNode.querySelector('.hash').innerHTML);
}, false);

function copyTextToClipboard(text) {
const textArea = document.createElement('textarea');

textArea.style.position = 'fixed';
textArea.style.top = 0;
textArea.style.left = 0;
textArea.style.width = '2em';
textArea.style.height = '2em';
textArea.style.padding = 0;
textArea.style.border = 'none';
textArea.style.outline = 'none';
textArea.style.boxShadow = 'none';
textArea.style.background = 'transparent';
textArea.value = text;
document.body.appendChild(textArea);
textArea.select();
try {
document.execCommand('copy');
} catch (err) {
console.log('Oops, unable to copy');
}
document.body.removeChild(textArea);
}

}(document, window));
9 changes: 9 additions & 0 deletions assets/js/defaultSelection.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
(function(document) {
//display detail of first commit if no one selected before
setTimeout(() => {
if (!document.querySelector('.commit.selected')) {
document.querySelector('.commit').click();
}
});

}(document));
38 changes: 38 additions & 0 deletions assets/js/keyboard.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
(function(document, global) {

const commitsEle = document.querySelector('.commits');
const lineHeight = height(document.querySelector('.commit'));

document.querySelector('.commits').addEventListener('keydown', (e) => {
if (e.keyCode !== 40 && e.keyCode !== 38) {
return;
}
e.preventDefault();
e.stopPropagation();

const selectedEle = document.querySelector('.commit.selected');

const nextEle = e.keyCode === 40 ? selectedEle.nextElementSibling : selectedEle.previousElementSibling;

if (!nextEle) {
return;
}
if (e.keyCode === 40 && nextEle.offsetTop + lineHeight > commitsEle.offsetHeight) {
commitsEle.scrollTop += lineHeight;
}
if (e.keyCode === 38 && nextEle.offsetTop < commitsEle.scrollTop) {
commitsEle.scrollTop -= lineHeight;
}

nextEle.click();
}, false);

function height(el) {

const styles = global.getComputedStyle(el);
const margin = parseFloat(styles.marginTop) + parseFloat(styles.marginBottom);

return Math.ceil(el.offsetHeight + margin);
}

}(document, window));
13 changes: 13 additions & 0 deletions assets/js/scrollPosition.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
(function(document, localStorage) {
//restore scroll position while detail changed
if (document.querySelector('.commit.selected')) {
document.querySelector('.commits').scrollTop = +localStorage.getItem('pos');
localStorage.setItem('pos', 0);
}

//record scroll position before detail gets changed
document.querySelector('.commits').addEventListener('click', () => {
localStorage.setItem('pos', document.querySelector('.commits').scrollTop);
}, false);

}(document, localStorage));
5 changes: 5 additions & 0 deletions assets/js/takefocus.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
(function(document) {
setTimeout(() => {
document.querySelector('.commits').focus();
});
}(document));
13 changes: 13 additions & 0 deletions assets/js/util.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
(function(global) {

global.getCommitNode = function(node) {
if (node.tagName === 'BODY') {
return;
}
if (node.classList.contains('commit')) {
return node;
}
return global.getCommitNode(node.parentNode);
};

}(window));
122 changes: 67 additions & 55 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,58 +1,70 @@
{
"name": "vscode-gitk",
"displayName": "gitk",
"description": "show commit log for selected source code information in an individual view",
"version": "1.0.5",
"publisher": "howardzuo",
"engines": {
"vscode": "^1.12.0"
"name": "vscode-gitk",
"displayName": "gitk",
"description": "show commit log for selected source code information in an individual view",
"version": "1.1.0",
"publisher": "howardzuo",
"engines": {
"vscode": "^1.12.0"
},
"scripts": {
"vscode:prepublish": "tsc -p ./",
"compile": "tsc -watch -p ./",
"postinstall": "node ./node_modules/vscode/bin/install"
},
"categories": [
"Debuggers"
],
"icon": "images/git-logo.png",
"bugs": {
"url": "https://github.com/leftstick/vscode-gitk/issues",
"email": "leftstick@qq.com"
},
"homepage": "https://github.com/leftstick/vscode-gitk/blob/master/README.md",
"repository": {
"type": "git",
"url": "https://github.com/leftstick/vscode-gitk.git"
},
"activationEvents": [
"onCommand:extension.gitk"
],
"license": "GPL-3.0",
"main": "./out/src",
"contributes": {
"menus": {
"explorer/context": [
{
"command": "extension.gitk",
"group": "sourcecontrol"
}
],
"editor/context": [
{
"command": "extension.gitk",
"group": "sourcecontrol"
}
]
},
"scripts": {
"vscode:prepublish": "tsc -p ./",
"compile": "tsc -watch -p ./",
"postinstall": "node ./node_modules/vscode/bin/install"
},
"categories": [
"Debuggers"
"commands": [
{
"command": "extension.gitk",
"title": "Gitk"
}
],
"icon": "images/git-logo.png",
"bugs": {
"url": "https://github.com/leftstick/vscode-gitk/issues",
"email": "leftstick@qq.com"
},
"homepage": "https://github.com/leftstick/vscode-gitk/blob/master/README.md",
"repository": {
"type": "git",
"url": "https://github.com/leftstick/vscode-gitk.git"
},
"activationEvents": [
"onCommand:extension.gitk"
],
"license": "GPL-3.0",
"main": "./out/src",
"contributes": {
"menus": {
"explorer/context": [{
"command": "extension.gitk",
"group": "sourcecontrol"
}],
"editor/context": [{
"command": "extension.gitk",
"group": "sourcecontrol"
}]
},
"commands": [{
"command": "extension.gitk",
"title": "Gitk"
}],
"keybindings": [{
"command": "extension.gitk",
"key": "alt+k"
}]
},
"devDependencies": {
"typescript": "^2.3.2",
"vscode": "^1.1.0",
"@types/node": "^7.0.18"
}
}
"keybindings": [
{
"command": "extension.gitk",
"key": "alt+k"
}
]
},
"devDependencies": {
"@types/lodash": "^4.14.64",
"@types/node": "^7.0.18",
"typescript": "^2.3.2",
"vscode": "^1.1.0"
},
"dependencies": {
"lodash.template": "^4.4.0"
}
}
Loading

0 comments on commit fb0c1ee

Please sign in to comment.