From a359c00746a46caf9f7b452ae2ed779d551272ed Mon Sep 17 00:00:00 2001 From: HEREYUA <1240335630@qq.com> Date: Tue, 26 Mar 2024 10:18:17 +0800 Subject: [PATCH 1/3] Change the focus of the issue title --- templates/repo/issue/new_form.tmpl | 2 +- web_src/js/features/repo-issue.js | 8 ++++++++ web_src/js/index.js | 2 ++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/templates/repo/issue/new_form.tmpl b/templates/repo/issue/new_form.tmpl index 058ea8d73ecce..4c165b2221c03 100644 --- a/templates/repo/issue/new_form.tmpl +++ b/templates/repo/issue/new_form.tmpl @@ -9,7 +9,7 @@ {{ctx.AvatarUtils.Avatar .SignedUser 40}}
- + {{if .PageIsComparePull}}
{{ctx.Locale.Tr "repo.pulls.title_wip_desc" (index .PullRequestWorkInProgressPrefixes 0)}}
{{end}} diff --git a/web_src/js/features/repo-issue.js b/web_src/js/features/repo-issue.js index 492428b327175..41cac0377822d 100644 --- a/web_src/js/features/repo-issue.js +++ b/web_src/js/features/repo-issue.js @@ -331,6 +331,14 @@ export function initRepoIssueReferenceRepositorySearch() { }); } +export function initRepoIssueTitleFocus() { + const issueTtitle = document.getElementById('issue_title'); + if (issueTtitle) { + issueTtitle.focus(); + issueTtitle.setSelectionRange(issueTtitle.value.length, issueTtitle.value.length); + } +} + export function initRepoIssueWipTitle() { $('.title_wip_desc > a').on('click', (e) => { e.preventDefault(); diff --git a/web_src/js/index.js b/web_src/js/index.js index abf0d469d18ed..586b25788f734 100644 --- a/web_src/js/index.js +++ b/web_src/js/index.js @@ -28,6 +28,7 @@ import { initRepoIssueDue, initRepoIssueReferenceRepositorySearch, initRepoIssueTimeTracking, + initRepoIssueTitleFocus, initRepoIssueWipTitle, initRepoPullRequestMergeInstruction, initRepoPullRequestAllowMaintainerEdit, @@ -154,6 +155,7 @@ onDomReady(() => { initArchivedLabelHandler(); initRepoIssueReferenceRepositorySearch(); initRepoIssueTimeTracking(); + initRepoIssueTitleFocus(); initRepoIssueWipTitle(); initRepoMigration(); initRepoMigrationStatusChecker(); From ae9d4f12b729405ccf38b5ce07f89910b2b36026 Mon Sep 17 00:00:00 2001 From: HEREYUA <1240335630@qq.com> Date: Tue, 26 Mar 2024 18:09:30 +0800 Subject: [PATCH 2/3] fix --- templates/repo/issue/new_form.tmpl | 2 +- web_src/js/features/repo-issue.js | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/templates/repo/issue/new_form.tmpl b/templates/repo/issue/new_form.tmpl index 4c165b2221c03..4121862707be0 100644 --- a/templates/repo/issue/new_form.tmpl +++ b/templates/repo/issue/new_form.tmpl @@ -9,7 +9,7 @@ {{ctx.AvatarUtils.Avatar .SignedUser 40}}
- + {{if .PageIsComparePull}}
{{ctx.Locale.Tr "repo.pulls.title_wip_desc" (index .PullRequestWorkInProgressPrefixes 0)}}
{{end}} diff --git a/web_src/js/features/repo-issue.js b/web_src/js/features/repo-issue.js index 41cac0377822d..6cacb65cd2f16 100644 --- a/web_src/js/features/repo-issue.js +++ b/web_src/js/features/repo-issue.js @@ -332,10 +332,10 @@ export function initRepoIssueReferenceRepositorySearch() { } export function initRepoIssueTitleFocus() { - const issueTtitle = document.getElementById('issue_title'); - if (issueTtitle) { - issueTtitle.focus(); - issueTtitle.setSelectionRange(issueTtitle.value.length, issueTtitle.value.length); + const issueTitle = document.getElementById('issue_title'); + if (issueTitle) { + issueTitle.focus(); + issueTitle.setSelectionRange(issueTitle.value.length, issueTitle.value.length); } } From 9eeab81a7719a4982d867a6b1345f8e3d215ec5c Mon Sep 17 00:00:00 2001 From: HEREYUA <1240335630@qq.com> Date: Wed, 27 Mar 2024 10:08:09 +0800 Subject: [PATCH 3/3] add autofocus-end.js --- templates/repo/issue/new_form.tmpl | 2 +- web_src/js/features/autofocus-end.js | 6 ++++++ web_src/js/features/repo-issue.js | 8 -------- web_src/js/index.js | 4 ++-- 4 files changed, 9 insertions(+), 11 deletions(-) create mode 100644 web_src/js/features/autofocus-end.js diff --git a/templates/repo/issue/new_form.tmpl b/templates/repo/issue/new_form.tmpl index 4121862707be0..88a6c39e522c0 100644 --- a/templates/repo/issue/new_form.tmpl +++ b/templates/repo/issue/new_form.tmpl @@ -9,7 +9,7 @@ {{ctx.AvatarUtils.Avatar .SignedUser 40}}
- + {{if .PageIsComparePull}}
{{ctx.Locale.Tr "repo.pulls.title_wip_desc" (index .PullRequestWorkInProgressPrefixes 0)}}
{{end}} diff --git a/web_src/js/features/autofocus-end.js b/web_src/js/features/autofocus-end.js new file mode 100644 index 0000000000000..da71ce9536d62 --- /dev/null +++ b/web_src/js/features/autofocus-end.js @@ -0,0 +1,6 @@ +export function initAutoFocusEnd() { + for (const el of document.querySelectorAll('.js-autofocus-end')) { + el.focus(); // expects only one such element on one page. If there are many, then the last one gets the focus. + el.setSelectionRange(el.value.length, el.value.length); + } +} diff --git a/web_src/js/features/repo-issue.js b/web_src/js/features/repo-issue.js index 6cacb65cd2f16..492428b327175 100644 --- a/web_src/js/features/repo-issue.js +++ b/web_src/js/features/repo-issue.js @@ -331,14 +331,6 @@ export function initRepoIssueReferenceRepositorySearch() { }); } -export function initRepoIssueTitleFocus() { - const issueTitle = document.getElementById('issue_title'); - if (issueTitle) { - issueTitle.focus(); - issueTitle.setSelectionRange(issueTitle.value.length, issueTitle.value.length); - } -} - export function initRepoIssueWipTitle() { $('.title_wip_desc > a').on('click', (e) => { e.preventDefault(); diff --git a/web_src/js/index.js b/web_src/js/index.js index 586b25788f734..4c707486bda97 100644 --- a/web_src/js/index.js +++ b/web_src/js/index.js @@ -13,6 +13,7 @@ import {initImageDiff} from './features/imagediff.js'; import {initRepoMigration} from './features/repo-migration.js'; import {initRepoProject} from './features/repo-projects.js'; import {initTableSort} from './features/tablesort.js'; +import {initAutoFocusEnd} from './features/autofocus-end.js'; import {initAdminUserListSearchForm} from './features/admin/users.js'; import {initAdminConfigs} from './features/admin/config.js'; import {initMarkupAnchors} from './markup/anchors.js'; @@ -28,7 +29,6 @@ import { initRepoIssueDue, initRepoIssueReferenceRepositorySearch, initRepoIssueTimeTracking, - initRepoIssueTitleFocus, initRepoIssueWipTitle, initRepoPullRequestMergeInstruction, initRepoPullRequestAllowMaintainerEdit, @@ -123,6 +123,7 @@ onDomReady(() => { initSshKeyFormParser(); initStopwatch(); initTableSort(); + initAutoFocusEnd(); initFindFileInRepo(); initCopyContent(); @@ -155,7 +156,6 @@ onDomReady(() => { initArchivedLabelHandler(); initRepoIssueReferenceRepositorySearch(); initRepoIssueTimeTracking(); - initRepoIssueTitleFocus(); initRepoIssueWipTitle(); initRepoMigration(); initRepoMigrationStatusChecker();