LoginSignup
1
0

More than 5 years have passed since last update.

GitLabのdiffを一括で折りたたむ [Collapse All]ボタンを追加するsnippet

Last updated at Posted at 2018-02-02

大量のコードをレビューする際(特に自動生成ファイルや画像ファイルが含まれている場合)には、一旦全てのDiffを折りたたんでからレビューを進めたいと思う事があります。

普通にあっても良さそうな機能ですが、現時点では実装されてません。
Feature Proposalとして、既に以下のページに上がっているのでそのうち実装されるとは思いますが・・。

[Workaround]

この機能が実装されるまでは、以下のページに記載されていた方法で[Collapse All]ボタンをDiffのページに追加する事ができます。

  1. Chrome を起動。
  2. [F12] をクリック。
  3. "Sources" をクリック。
  4. "Snippets" タブをクリック。
  5. "+ New snippet"をクリック。
  6. Snippetの名前を付けた後、以下のコードを貼り付け、保存する。
  7. 作成したSnippetを選択し、右クリックした後"Run"を選択する。
/*
* GiblabのDiffページに[Collapse All] ボタンを追加するsnippet
*/

// Collapse All ボタンの作成
function createCollapseAllButton() {
    var button = document.createElement('button');
    button.setAttribute('id', 'collapse-all');
    button.setAttribute('class', 'btn btn-default');
    button.setAttribute('type', 'button');
    button.textContent = 'Collapse All';

    return button;
}

// Collapse All ボタンをクリックした際のイベントハンドラ
function collapseAll(event) {
    $('.diff-file').find('div.nothing-here-block').each(function(i) {
        if (!$(this).is(':visible')) {
            $(this).parents('div.file-holder').find('div.file-title-flex-parent').trigger('click');
        }
    });
}

var buttons = document.getElementsByClassName('inline-parallel-buttons')[0];
buttons.insertBefore(createCollapseAllButton(), buttons.firstChild);

// Collapse All ボタンを有効化
document.getElementById('collapse-all').addEventListener('click', collapseAll, false);

[参考URL]
Button to collapse all diffs (#24679) · Issues · GitLab.org / GitLab Community Edition · GitLab

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0