Skip to content

Commit 3d30e8f

Browse files
committed
common function for joining tree path
1 parent 9ca6274 commit 3d30e8f

File tree

1 file changed

+19
-13
lines changed

1 file changed

+19
-13
lines changed

web_src/js/features/repo-editor.js

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -91,12 +91,25 @@ export function initRepoEditor() {
9191
$('#commit-button').text($(this).attr('button_text'));
9292
});
9393

94+
const joinTreePath = ($fileNameEl) => {
95+
const parts = [];
96+
$('.breadcrumb span.section').each(function () {
97+
const element = $(this);
98+
if (element.find('a').length) {
99+
parts.push(element.find('a').text());
100+
} else {
101+
parts.push(element.text());
102+
}
103+
});
104+
if ($fileNameEl.val()) parts.push($fileNameEl.val());
105+
$('#tree_path').val(parts.join('/'));
106+
};
107+
94108
const $editFilename = $('#file-name');
95109
$editFilename.on('input', function () {
96110
let value;
97-
let parts;
111+
const parts = $(this).val().split('/');
98112

99-
parts = $(this).val().split('/');
100113
if (parts.length > 1) {
101114
for (let i = 0; i < parts.length; ++i) {
102115
value = parts[i];
@@ -111,17 +124,8 @@ export function initRepoEditor() {
111124
$(this)[0].setSelectionRange(0, 0);
112125
}
113126
}
114-
parts = [];
115-
$('.breadcrumb span.section').each(function () {
116-
const element = $(this);
117-
if (element.find('a').length) {
118-
parts.push(element.find('a').text());
119-
} else {
120-
parts.push(element.text());
121-
}
122-
});
123-
if ($(this).val()) parts.push($(this).val());
124-
$('#tree_path').val(parts.join('/'));
127+
128+
joinTreePath($(this));
125129
});
126130

127131
$editFilename.on('keyup', function (e) {
@@ -136,6 +140,8 @@ export function initRepoEditor() {
136140
$section.last().remove();
137141
$divider.last().remove();
138142
}
143+
144+
joinTreePath($(this));
139145
});
140146

141147
const $editArea = $('.repository.editor textarea#edit_area');

0 commit comments

Comments
 (0)