// File: JD297[P]cedit/src/cedit.cpp
// Function: cedit::Cedit::event_backspace()
void Cedit::event_backspace()
{
	// If at beginning of line and current line is not the first line
	if(this->currentIndex == 0 && this->contentIt != this->content.begin())
	{
		this->scrollup();

		// When the line has no content with exception of "\n"
		if(std::prev(this->contentIt)->length() != 1)
		{
			this->contentIt = std::prev(this->contentIt);

			this->currentIndex = this->contentIt->length()-1;
			this->savedIndex = this->contentIt->length()-1;

			if(this->contentIt->length() > 0) {
				// Append the complete line to the previous line
				this->contentIt->append(std::next(this->contentIt)->substr(0));

				// Delete the first line break in the current line
				this->contentIt->erase(this->contentIt->find("\n"), 1);
			}

			// Delete the line from where the list was copied from
			this->content.erase(std::next(this->contentIt));
		}
		else if(std::prev(this->contentIt)->length() == 1)
		{
			// Delete the previous line with the "\n". The line will be poped one row up
			this->content.erase(std::prev(this->contentIt));

			this->currentIndex = 0;
			this->savedIndex = 0;
		}
	}
	else if(!(this->currentIndex == 0 && this->contentIt == this->content.begin()))
	{
		// Deletes the character that is in front of the cursor
		this->contentIt->erase(this->currentIndex-1, 1);

		this->currentIndex--;
		this->savedIndex = this->currentIndex;
		this->refreshDisplay = false;
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x110, %rsp            # imm = 0x110
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rcx
movq %rcx, -0xd8(%rbp)
xorl %eax, %eax
cmpq $0x0, 0x50(%rcx)
movb %al, -0xc9(%rbp)
jne 0x5ddd
movq -0xd8(%rbp), %rdi
movq %rdi, %rax
addq $0x18, %rax
movq %rax, -0xe0(%rbp)
callq 0x91c0
movq -0xe0(%rbp), %rdi
movq %rax, -0x10(%rbp)
leaq -0x10(%rbp), %rsi
callq 0x9310
movb %al, -0xc9(%rbp)
movb -0xc9(%rbp), %al
testb $0x1, %al
jne 0x5dec
jmp 0x60b5
movq -0xd8(%rbp), %rdi
callq 0x8590
movq -0xd8(%rbp), %rax
movq 0x18(%rax), %rax
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rdi
movl $0x1, %esi
callq 0x9280
movq %rax, -0x18(%rbp)
leaq -0x18(%rbp), %rdi
callq 0x92f0
movq %rax, %rdi
callq 0x4640
cmpq $0x1, %rax
je 0x5ff9
movq -0xd8(%rbp), %rax
movq 0x18(%rax), %rax
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rdi
movl $0x1, %esi
callq 0x9280
movq -0xd8(%rbp), %rdi
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rax
movq %rax, 0x18(%rdi)
addq $0x18, %rdi
callq 0x92f0
movq %rax, %rdi
callq 0x4640
movq -0xd8(%rbp), %rdi
subq $0x1, %rax
movq %rax, 0x50(%rdi)
addq $0x18, %rdi
callq 0x92f0
movq %rax, %rdi
callq 0x4640
movq -0xd8(%rbp), %rdi
subq $0x1, %rax
movq %rax, 0x58(%rdi)
addq $0x18, %rdi
callq 0x92f0
movq %rax, %rdi
callq 0x4640
cmpq $0x0, %rax
jbe 0x5fa9
movq -0xd8(%rbp), %rdi
addq $0x18, %rdi
callq 0x92f0
movq %rax, %rcx
movq -0xd8(%rbp), %rax
movq %rcx, -0xf0(%rbp)
movq 0x18(%rax), %rax
movq %rax, -0x60(%rbp)
movq -0x60(%rbp), %rdi
movl $0x1, %esi
callq 0x9d90
movq %rax, -0x58(%rbp)
leaq -0x58(%rbp), %rdi
callq 0x92f0
movq %rax, %rsi
xorl %eax, %eax
movl %eax, %edx
leaq -0x50(%rbp), %rdi
movq %rdi, -0xe8(%rbp)
movq $-0x1, %rcx
callq 0x4430
movq -0xf0(%rbp), %rdi
movq -0xe8(%rbp), %rsi
callq 0x4760
jmp 0x5f36
leaq -0x50(%rbp), %rdi
callq 0x42d0
movq -0xd8(%rbp), %rdi
addq $0x18, %rdi
callq 0x92f0
movq -0xd8(%rbp), %rdi
movq %rax, -0xf8(%rbp)
addq $0x18, %rdi
callq 0x92f0
movq %rax, %rdi
leaq 0x8308(%rip), %rsi      # 0xe278
xorl %eax, %eax
movl %eax, %edx
callq 0x4780
movq -0xf8(%rbp), %rdi
movq %rax, %rsi
movl $0x1, %edx
callq 0x4100
jmp 0x5fa9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
leaq -0x50(%rbp), %rdi
callq 0x42d0
jmp 0x6169
movq -0xd8(%rbp), %rax
movq 0x18(%rax), %rax
movq %rax, -0x88(%rbp)
movq -0x88(%rbp), %rdi
movl $0x1, %esi
callq 0x9d90
movq %rax, -0x80(%rbp)
leaq -0x78(%rbp), %rdi
leaq -0x80(%rbp), %rsi
callq 0x9dc0
movq -0xd8(%rbp), %rdi
movq -0x78(%rbp), %rsi
callq 0x9de0
movq %rax, -0x90(%rbp)
jmp 0x60b0
movq -0xd8(%rbp), %rax
movq 0x18(%rax), %rax
movq %rax, -0xa0(%rbp)
movq -0xa0(%rbp), %rdi
movl $0x1, %esi
callq 0x9280
movq %rax, -0x98(%rbp)
leaq -0x98(%rbp), %rdi
callq 0x92f0
movq %rax, %rdi
callq 0x4640
cmpq $0x1, %rax
jne 0x60ae
movq -0xd8(%rbp), %rax
movq 0x18(%rax), %rax
movq %rax, -0xb8(%rbp)
movq -0xb8(%rbp), %rdi
movl $0x1, %esi
callq 0x9280
movq %rax, -0xb0(%rbp)
leaq -0xa8(%rbp), %rdi
leaq -0xb0(%rbp), %rsi
callq 0x9dc0
movq -0xd8(%rbp), %rdi
movq -0xa8(%rbp), %rsi
callq 0x9de0
movq %rax, %rcx
movq -0xd8(%rbp), %rax
movq %rcx, -0xc0(%rbp)
movq $0x0, 0x50(%rax)
movq $0x0, 0x58(%rax)
jmp 0x60b0
jmp 0x6160
movq -0xd8(%rbp), %rcx
xorl %eax, %eax
cmpq $0x0, 0x50(%rcx)
movb %al, -0xf9(%rbp)
jne 0x6105
movq -0xd8(%rbp), %rdi
movq %rdi, %rax
addq $0x18, %rax
movq %rax, -0x108(%rbp)
callq 0x91c0
movq -0x108(%rbp), %rdi
movq %rax, -0xc8(%rbp)
leaq -0xc8(%rbp), %rsi
callq 0x9e30
movb %al, -0xf9(%rbp)
movb -0xf9(%rbp), %al
xorb $-0x1, %al
testb $0x1, %al
jne 0x6113
jmp 0x615e
movq -0xd8(%rbp), %rdi
addq $0x18, %rdi
callq 0x92f0
movq %rax, %rdi
movq -0xd8(%rbp), %rax
movq 0x50(%rax), %rsi
subq $0x1, %rsi
movl $0x1, %edx
callq 0x4100
movq -0xd8(%rbp), %rax
movq 0x50(%rax), %rcx
addq $-0x1, %rcx
movq %rcx, 0x50(%rax)
movq 0x50(%rax), %rcx
movq %rcx, 0x58(%rax)
movb $0x0, 0x6c(%rax)
jmp 0x6160
addq $0x110, %rsp            # imm = 0x110
popq %rbp
retq
movq -0x68(%rbp), %rdi
callq 0x4700
nopw %cs:(%rax,%rax)