Browse Source

Merge pull request #117 from blackjid/indent_with_tab_key

Adds support to indent with the tab key
master
Sindre Sorhus 9 years ago
parent
commit
999729a3f0
  1. 24
      extension/content.js
  2. 1
      readme.md

24
extension/content.js

@ -299,6 +299,30 @@ function markMergeCommitsInList() {
});
}
function indentInput(el, size = 4) {
el.focus();
const value = el.value;
const selectionStart = el.selectionStart;
const indentSize = (size - el.selectionEnd % size) || size;
const indentationText = ' '.repeat(indentSize);
el.value = value.slice(0, selectionStart) + indentationText + value.slice(el.selectionEnd);
el.selectionEnd = el.selectionStart = selectionStart + indentationText.length;
}
// Support indent with tab key in textarea elements
$(document).on('keydown', event => {
// Check event.target instead of using a delegate, because Sprint doesn't support them
if (!$(event.target).is('textarea')) {
return;
}
if (event.which === 9) {
event.preventDefault();
indentInput(event.target);
return false;
}
});
// Prompt user to confirm erasing a comment with the Cancel button
$(document).on('click', event => {
// Check event.target instead of using a delegate, because Sprint doesn't support them

1
readme.md

@ -27,6 +27,7 @@ My hope is that GitHub will notice and implement some of these much needed impro
- Removes annoying hover effect in the repo file browser
- Removes the comment box toolbar
- Moves the dashboard organization switcher to the right column
- Supports indenting with the tab key in textareas
And [lots](extension/content.css) [more...](extension/content.js)

Loading…
Cancel
Save