<commit_before>package main

import (
	"github.com/nsf/tulib"
)

//----------------------------------------------------------------------------
// view_tree
//----------------------------------------------------------------------------

type view_tree struct {
	// At the same time only one of these groups can be valid:
	// 1) 'left', 'right' and 'split'
	// 2) 'top', 'bottom' and 'split'
	// 3) 'leaf'
	parent     *view_tree
	left       *view_tree
	top        *view_tree
	right      *view_tree
	bottom     *view_tree
	leaf       *view
	split      float32
	tulib.Rect // updated with 'resize' call
}

func new_view_tree_leaf(parent *view_tree, v *view) *view_tree {
	return &view_tree{
		parent: parent,
		leaf:   v,
	}
}

func (v *view_tree) split_vertically() {
	top := v.leaf
	bottom := new_view(top.ctx, top.buf)
	*v = view_tree{
		parent: v.parent,
		top:    new_view_tree_leaf(v, top),
		bottom: new_view_tree_leaf(v, bottom),
		split:  0.5,
	}
}

func (v *view_tree) split_horizontally() {
	left := v.leaf
	right := new_view(left.ctx, left.buf)
	*v = view_tree{
		parent: v.parent,
		left:   new_view_tree_leaf(v, left),
		right:  new_view_tree_leaf(v, right),
		split:  0.5,
	}
}<commit_msg>On view split, use the view_location from the view we're splitting.<commit_after>package main

import (
	"github.com/nsf/tulib"
)

//----------------------------------------------------------------------------
// view_tree
//----------------------------------------------------------------------------

type view_tree struct {
	// At the same time only one of these groups can be valid:
	// 1) 'left', 'right' and 'split'
	// 2) 'top', 'bottom' and 'split'
	// 3) 'leaf'
	parent     *view_tree
	left       *view_tree
	top        *view_tree
	right      *view_tree
	bottom     *view_tree
	leaf       *view
	split      float32
	tulib.Rect // updated with 'resize' call
}

func new_view_tree_leaf(parent *view_tree, v *view) *view_tree {
	return &view_tree{
		parent: parent,
		leaf:   v,
	}
}

func (v *view_tree) split_vertically() {
	top := v.leaf
	bottom := new_view(top.ctx, top.buf)
	bottom.view_location = top.view_location
	*v = view_tree{
		parent: v.parent,
		top:    new_view_tree_leaf(v, top),
		bottom: new_view_tree_leaf(v, bottom),
		split:  0.5,
	}
}

func (v *view_tree) split_horizontally() {
	left := v.leaf
	right := new_view(left.ctx, left.buf)
	right.view_location = left.view_location
	*v = view_tree{
		parent: v.parent,
		left:   new_view_tree_leaf(v, left),
		right:  new_view_tree_leaf(v, right),
		split:  0.5,
	}
}
{'fraction_non_alphanumeric': 0.23818897637795275, 'fraction_numerical': 0.007086614173228346, 'mean_word_length': 2.017814726840855, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1591399', 'n_tokens_mistral': 934, 'n_tokens_neox': 903, 'n_words': 224}