diff options
Diffstat (limited to 'app/assets/javascripts/blob/utils.js')
-rw-r--r-- | app/assets/javascripts/blob/utils.js | 26 |
1 files changed, 14 insertions, 12 deletions
diff --git a/app/assets/javascripts/blob/utils.js b/app/assets/javascripts/blob/utils.js index bbc061dd36e..b2400a4b224 100644 --- a/app/assets/javascripts/blob/utils.js +++ b/app/assets/javascripts/blob/utils.js @@ -1,16 +1,18 @@ -import Editor from '~/editor/source_editor'; +import { getBaseURL } from '~/lib/utils/url_utility'; -export function initSourceEditor({ el, ...args }) { - const editor = new Editor({ - scrollbar: { - alwaysConsumeMouseWheel: false, - }, - }); +const blameLinesPerPage = document.querySelector('.js-per-page')?.dataset?.blamePerPage; - return editor.createInstance({ - el, - ...args, - }); -} +export const getPageParamValue = (lineNum, blamePerPage = blameLinesPerPage) => { + if (!blamePerPage) return ''; + const page = Math.ceil(parseInt(lineNum, 10) / parseInt(blamePerPage, 10)); + return page <= 1 ? '' : page; +}; + +export const getPageSearchString = (path, page) => { + if (!page) return ''; + const url = new URL(path, getBaseURL()); + url.searchParams.set('page', page); + return url.search; +}; export default () => ({}); |