Skip to content

Commit ec15729

Browse files
committed
BLENDER: Add Line Length indicator for cursor
1 parent 9768bce commit ec15729

File tree

2 files changed

+90
-1
lines changed

2 files changed

+90
-1
lines changed

templates/repo/editor/commit_form.tmpl

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,58 @@
1313
</div>
1414
<div class="field">
1515
<textarea name="commit_message" placeholder="{{ctx.Locale.Tr "repo.editor.commit_message_desc"}}" rows="5">{{.commit_message}}</textarea>
16+
<script>
17+
(function () {
18+
const textarea = document.querySelector('.commit-form textarea[name="commit_message"]');
19+
if (!textarea) return;
20+
21+
const statusbar = document.createElement('div');
22+
statusbar.className = 'editor-statusbar';
23+
24+
const autosave = document.createElement('span');
25+
autosave.className = 'autosave';
26+
27+
const lines = document.createElement('span');
28+
lines.className = 'lines';
29+
lines.textContent = '1';
30+
31+
const words = document.createElement('span');
32+
words.className = 'words';
33+
words.textContent = '1';
34+
35+
const cursor = document.createElement('span');
36+
cursor.className = 'cursor';
37+
cursor.textContent = '1:1';
38+
39+
statusbar.appendChild(autosave);
40+
statusbar.appendChild(lines);
41+
statusbar.appendChild(words);
42+
statusbar.appendChild(cursor);
43+
textarea.parentElement.appendChild(statusbar);
44+
45+
function updateStatus() {
46+
const value = textarea.value;
47+
const pos = textarea.selectionStart;
48+
49+
const linesArray = value.substr(0, pos).split('\n');
50+
const line = linesArray.length;
51+
const column = linesArray[linesArray.length - 1].length + 1;
52+
53+
const totalLines = value.split('\n').length;
54+
const totalWords = (value.match(/\b\w+\b/g) || []).length;
55+
56+
lines.textContent = totalLines.toString();
57+
words.textContent = totalWords.toString();
58+
cursor.textContent = `${line}:${column}`;
59+
}
60+
61+
textarea.addEventListener('input', updateStatus);
62+
textarea.addEventListener('click', updateStatus);
63+
textarea.addEventListener('keyup', updateStatus);
64+
updateStatus();
65+
})();
66+
</script>
67+
1668
</div>
1769
<div class="inline field">
1870
<div class="ui checkbox">

web_src/js/components/PullRequestMergeForm.vue

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@ const mergeStyleAllowedCount = ref(0);
2626
const showMergeStyleMenu = ref(false);
2727
const showActionForm = ref(false);
2828
29+
const mergeMessageTextarea = ref<HTMLTextAreaElement | null>(null);
30+
const cursorLine = ref(1);
31+
const cursorColumn = ref(1);
32+
const wordCount = ref(1);
33+
const lineCount = ref(1);
34+
2935
const mergeButtonStyleClass = computed(() => {
3036
if (mergeForm.value.allOverridableChecksOk) return 'primary';
3137
return autoMergeWhenSucceed.value ? 'primary' : 'red';
@@ -76,6 +82,22 @@ function switchMergeStyle(name: string, autoMerge = false) {
7682
function clearMergeMessage() {
7783
mergeMessageFieldValue.value = mergeForm.value.defaultMergeMessage;
7884
}
85+
86+
function updateCursorPosition() {
87+
const textarea = mergeMessageTextarea.value;
88+
if (!textarea) return;
89+
90+
const pos = textarea.selectionStart ?? 0;
91+
const value = textarea.value;
92+
93+
const lines = value.substring(0, pos).split('\n');
94+
cursorLine.value = lines.length;
95+
cursorColumn.value = lines[lines.length - 1].length + 1;
96+
97+
lineCount.value = textarea.value.split('\n').length;
98+
wordCount.value = textarea.value.trim().split(/\s+/).filter(Boolean).length;
99+
}
100+
79101
</script>
80102

81103
<template>
@@ -105,7 +127,22 @@ function clearMergeMessage() {
105127
<input type="text" name="merge_title_field" v-model="mergeTitleFieldValue">
106128
</div>
107129
<div class="field">
108-
<textarea name="merge_message_field" rows="5" :placeholder="mergeForm.mergeMessageFieldPlaceHolder" v-model="mergeMessageFieldValue"/>
130+
<textarea
131+
ref="mergeMessageTextarea"
132+
name="merge_message_field"
133+
rows="5"
134+
:placeholder="mergeForm.mergeMessageFieldPlaceHolder"
135+
v-model="mergeMessageFieldValue"
136+
@click="updateCursorPosition"
137+
@keyup="updateCursorPosition"
138+
@input="updateCursorPosition"
139+
/>
140+
<div class="editor-statusbar">
141+
<span class="autosave"></span>
142+
<span class="lines">{{ lineCount }}</span>
143+
<span class="words">{{ wordCount }}</span>
144+
<span class="cursor">{{ cursorLine }}:{{ cursorColumn }}</span>
145+
</div>
109146
<template v-if="mergeMessageFieldValue !== mergeForm.defaultMergeMessage">
110147
<button @click.prevent="clearMergeMessage" class="btn tw-mt-1 tw-p-1 interact-fg" :data-tooltip-content="mergeForm.textClearMergeMessageHint">
111148
{{ mergeForm.textClearMergeMessage }}

0 commit comments

Comments
 (0)