Code region */
| 1886 | |
| 1887 | /* Code region */ |
| 1888 | void CodeEdit::create_code_region() { |
| 1889 | // Abort if there is no selected text. |
| 1890 | if (!has_selection()) { |
| 1891 | return; |
| 1892 | } |
| 1893 | // Check that region tag find a comment delimiter and is valid. |
| 1894 | if (code_region_start_string.is_empty()) { |
| 1895 | WARN_PRINT_ONCE("Cannot create code region without any one line comment delimiters"); |
| 1896 | return; |
| 1897 | } |
| 1898 | String region_name = atr(ETR("New Code Region")); |
| 1899 | |
| 1900 | begin_complex_operation(); |
| 1901 | begin_multicaret_edit(); |
| 1902 | Vector<Point2i> line_ranges = get_line_ranges_from_carets(true, false); |
| 1903 | |
| 1904 | // Add start and end region tags. |
| 1905 | int line_offset = 0; |
| 1906 | for (Point2i line_range : line_ranges) { |
| 1907 | insert_text("\n" + code_region_end_string, line_range.y + line_offset, get_line(line_range.y + line_offset).length()); |
| 1908 | insert_line_at(line_range.x + line_offset, code_region_start_string + " " + region_name); |
| 1909 | fold_line(line_range.x + line_offset); |
| 1910 | line_offset += 2; |
| 1911 | } |
| 1912 | int first_region_start = line_ranges[0].x; |
| 1913 | |
| 1914 | // Select name of the first region to allow quick edit. |
| 1915 | remove_secondary_carets(); |
| 1916 | int tag_length = code_region_start_string.length() + region_name.length() + 1; |
| 1917 | select(first_region_start, code_region_start_string.length() + 1, first_region_start, tag_length); |
| 1918 | |
| 1919 | end_multicaret_edit(); |
| 1920 | end_complex_operation(); |
| 1921 | } |
| 1922 | |
| 1923 | String CodeEdit::get_code_region_start_tag() const { |
| 1924 | return code_region_start_tag; |
no test coverage detected