Skip to content

Commit 1261dd6

Browse files
authored
When the title in the issue has a value, set the text cursor at the end of the text. (#30090)
Fix: [#25055](#25055) Before ![image](https://github.com/go-gitea/gitea/assets/37935145/1b89cd7b-4fa3-49aa-9b5e-a8413add436e) After ![image](https://github.com/go-gitea/gitea/assets/37935145/fa808f8d-d3ce-4245-a4fe-dd0282ba3fdf) ps: I've noticed that we are gradually replacing jQuery, so I didn't use jQuery here.
1 parent ce3c351 commit 1261dd6

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed

templates/repo/issue/new_form.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
{{ctx.AvatarUtils.Avatar .SignedUser 40}}
1010
<div class="ui segment content tw-my-0">
1111
<div class="field">
12-
<input name="title" id="issue_title" placeholder="{{ctx.Locale.Tr "repo.milestones.title"}}" value="{{if .TitleQuery}}{{.TitleQuery}}{{else if .IssueTemplateTitle}}{{.IssueTemplateTitle}}{{else}}{{.title}}{{end}}" autofocus required maxlength="255" autocomplete="off">
12+
<input name="title" class="js-autofocus-end" id="issue_title" placeholder="{{ctx.Locale.Tr "repo.milestones.title"}}" value="{{if .TitleQuery}}{{.TitleQuery}}{{else if .IssueTemplateTitle}}{{.IssueTemplateTitle}}{{else}}{{.title}}{{end}}" required maxlength="255" autocomplete="off">
1313
{{if .PageIsComparePull}}
1414
<div class="title_wip_desc" data-wip-prefixes="{{JsonUtils.EncodeToString .PullRequestWorkInProgressPrefixes}}">{{ctx.Locale.Tr "repo.pulls.title_wip_desc" (index .PullRequestWorkInProgressPrefixes 0)}}</div>
1515
{{end}}

web_src/js/features/autofocus-end.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export function initAutoFocusEnd() {
2+
for (const el of document.querySelectorAll('.js-autofocus-end')) {
3+
el.focus(); // expects only one such element on one page. If there are many, then the last one gets the focus.
4+
el.setSelectionRange(el.value.length, el.value.length);
5+
}
6+
}

web_src/js/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {initImageDiff} from './features/imagediff.js';
1313
import {initRepoMigration} from './features/repo-migration.js';
1414
import {initRepoProject} from './features/repo-projects.js';
1515
import {initTableSort} from './features/tablesort.js';
16+
import {initAutoFocusEnd} from './features/autofocus-end.js';
1617
import {initAdminUserListSearchForm} from './features/admin/users.js';
1718
import {initAdminConfigs} from './features/admin/config.js';
1819
import {initMarkupAnchors} from './markup/anchors.js';
@@ -122,6 +123,7 @@ onDomReady(() => {
122123
initSshKeyFormParser();
123124
initStopwatch();
124125
initTableSort();
126+
initAutoFocusEnd();
125127
initFindFileInRepo();
126128
initCopyContent();
127129

0 commit comments

Comments
 (0)